mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Fix CPU bitmask truncation (1 of 2)
@ 2003-01-02 19:11 Bjorn Helgaas
  0 siblings, 0 replies; only message in thread
From: Bjorn Helgaas @ 2003-01-02 19:11 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: linux-kernel

The consensus is that this fixes a real bug in 2.4.20.  The
rationale is (in Linus' words):

>         1 << cpu

> is clearly an int, and as such will have undefined behaviour for cpu >
> bits-of-int.

> The promotion to unsigned long happens _after_ the shift has already
> happened as an int, since nothing in the sub-expression needs promotion
> per se.

I'll send the initialization patch separately, in case you don't
want that one.

diff -Nru a/kernel/sched.c b/kernel/sched.c
--- a/kernel/sched.c	Mon Dec 16 11:58:42 2002
+++ b/kernel/sched.c	Mon Dec 16 11:58:42 2002
@@ -116,7 +116,7 @@
 
 #define idle_task(cpu) (init_tasks[cpu_number_map(cpu)])
 #define can_schedule(p,cpu) \
-	((p)->cpus_runnable & (p)->cpus_allowed & (1 << cpu))
+	((p)->cpus_runnable & (p)->cpus_allowed & (1UL << cpu))
 
 #else
 
@@ -359,7 +359,7 @@
 	if (task_on_runqueue(p))
 		goto out;
 	add_to_runqueue(p);
-	if (!synchronous || !(p->cpus_allowed & (1 << smp_processor_id())))
+	if (!synchronous || !(p->cpus_allowed & (1UL << smp_processor_id())))
 		reschedule_idle(p);
 	success = 1;
 out:




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-01-02 19:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-02 19:11 [PATCH] Fix CPU bitmask truncation (1 of 2) Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®