diff options
author | Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> | 2014-12-05 07:22:22 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2015-01-14 07:34:15 -0500 |
commit | 1f8a7633094b7886c0677b78ba60b82e501f3ce6 (patch) | |
tree | 35b1e774960265e9463b4985dca4f09c3d2b9f26 /kernel/sched | |
parent | a8b686b3af4419f92e0ea5be1c76fb68363df8e6 (diff) |
sched/debug: Fix potential call to __ffs(0) in sched_show_task()
"struct task_struct"->state is "volatile long" and __ffs() warns that
"Undefined if no bit exists, so code should check against 0 first."
Therefore, at expression
state = p->state ? __ffs(p->state) + 1 : 0;
in sched_show_task(), CPU might see "p->state" before "?" as "non-zero"
but "p->state" after "?" as "zero", which could result in
"state >= sizeof(stat_nam)" being true and bogus '?' is printed.
This patch changes "state" from "unsigned int" to "unsigned long" and
save "p->state" before calling __ffs(), in order to avoid potential call
to __ffs(0).
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/201412052131.GCE35924.FVHFOtLOJOMQFS@I-love.SAKURA.ne.jp
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/sched')
-rw-r--r-- | kernel/sched/core.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 56c9b79772bd..816c17203c16 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
@@ -4508,9 +4508,10 @@ void sched_show_task(struct task_struct *p) | |||
4508 | { | 4508 | { |
4509 | unsigned long free = 0; | 4509 | unsigned long free = 0; |
4510 | int ppid; | 4510 | int ppid; |
4511 | unsigned state; | 4511 | unsigned long state = p->state; |
4512 | 4512 | ||
4513 | state = p->state ? __ffs(p->state) + 1 : 0; | 4513 | if (state) |
4514 | state = __ffs(state) + 1; | ||
4514 | printk(KERN_INFO "%-15.15s %c", p->comm, | 4515 | printk(KERN_INFO "%-15.15s %c", p->comm, |
4515 | state < sizeof(stat_nam) - 1 ? stat_nam[state] : '?'); | 4516 | state < sizeof(stat_nam) - 1 ? stat_nam[state] : '?'); |
4516 | #if BITS_PER_LONG == 32 | 4517 | #if BITS_PER_LONG == 32 |