linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Jan Beulich <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: torvalds@linux-foundation.org, linux-kernel@vger.kernel.org,
	riel@redhat.com, hpa@zytor.com, JBeulich@suse.com,
	peterz@infradead.org, tglx@linutronix.de, jbeulich@suse.com,
	mingo@kernel.org
Subject: [tip:sched/urgent] sched/fair: Avoid using uninitialized variable in preferred_group_nid()
Date: Wed, 28 Jan 2015 06:29:25 -0800	[thread overview]
Message-ID: <tip-81907478c4311a679849216abf723999184ab984@git.kernel.org> (raw)
In-Reply-To: <54C2139202000078000588F7@mail.emea.novell.com>

Commit-ID:  81907478c4311a679849216abf723999184ab984
Gitweb:     http://git.kernel.org/tip/81907478c4311a679849216abf723999184ab984
Author:     Jan Beulich <JBeulich@suse.com>
AuthorDate: Fri, 23 Jan 2015 08:25:38 +0000
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 28 Jan 2015 13:14:12 +0100

sched/fair: Avoid using uninitialized variable in preferred_group_nid()

At least some gcc versions - validly afaict - warn about potentially
using max_group uninitialized: There's no way the compiler can prove
that the body of the conditional where it and max_faults get set/
updated gets executed; in fact, without knowing all the details of
other scheduler code, I can't prove this either.

Generally the necessary change would appear to be to clear max_group
prior to entering the inner loop, and break out of the outer loop when
it ends up being all clear after the inner one. This, however, seems
inefficient, and afaict the same effect can be achieved by exiting the
outer loop when max_faults is still zero after the inner loop.

[ mingo: changed the solution to zero initialization: uninitialized_var()
  needs to die, as it's an actively dangerous construct: if in the future
  a known-proven-good piece of code is changed to have a true, buggy
  uninitialized variable, the compiler warning is then supressed...

  The better long term solution is to clean up the code flow, so that
  even simple minded compilers (and humans!) are able to read it without
  getting a headache.  ]

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/54C2139202000078000588F7@mail.emea.novell.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 40667cb..fe331fc 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1730,7 +1730,7 @@ static int preferred_group_nid(struct task_struct *p, int nid)
 	nodes = node_online_map;
 	for (dist = sched_max_numa_distance; dist > LOCAL_DISTANCE; dist--) {
 		unsigned long max_faults = 0;
-		nodemask_t max_group;
+		nodemask_t max_group = NODE_MASK_NONE;
 		int a, b;
 
 		/* Are there nodes at this distance from each other? */

  parent reply	other threads:[~2015-01-28 21:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-23  8:25 sched/fair: avoid using uninitialized variable in preferred_group_nid() Jan Beulich
2015-01-23  9:54 ` Peter Zijlstra
2015-01-23 10:01   ` Jan Beulich
2015-01-28 14:29 ` tip-bot for Jan Beulich [this message]
2015-01-28 14:46   ` [tip:sched/urgent] sched/fair: Avoid " Jan Beulich
2015-01-28 15:37     ` Peter Zijlstra
2015-02-09  8:21       ` Ingo Molnar
2015-02-09 11:37         ` Peter Zijlstra
2015-02-09 11:41           ` Jan Beulich
2015-02-18 17:10           ` [tip:sched/core] sched/numa: Avoid some pointless iterations tip-bot for Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-81907478c4311a679849216abf723999184ab984@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=JBeulich@suse.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).