[PATCH][2.6] first/next_cpu returns values > NR_CPUS

From: Zwane Mwaikambo
Date: Sat Jul 31 2004 - 15:49:59 EST


The following caused some fireworks whilst merging i386 cpu hotplug.

any_online_cpu(0x2) returns 32 on i386 if we're forced to continue past
the only set bit due to the additional find_first_bit in the
find_next_bit i386 implementation. Not wanting to change current
behaviour in the bitops primitives and since the NR_CPUS thing is a
cpumask issue, i've opted to fix next_cpu() and first_cpu() instead.

Signed-off-by: Zwane Mwaikambo <zwane@xxxxxxxxxxx>

Index: linux-2.6.8-rc2-mm1-lch/include/linux/cpumask.h
===================================================================
RCS file: /home/cvsroot/linux-2.6.8-rc2-mm1/include/linux/cpumask.h,v
retrieving revision 1.1.1.1
diff -u -p -B -r1.1.1.1 cpumask.h
--- linux-2.6.8-rc2-mm1-lch/include/linux/cpumask.h 28 Jul 2004 14:35:22 -0000 1.1.1.1
+++ linux-2.6.8-rc2-mm1-lch/include/linux/cpumask.h 31 Jul 2004 17:57:12 -0000
@@ -207,13 +207,19 @@ static inline void __cpus_shift_left(cpu
#define first_cpu(src) __first_cpu(&(src), NR_CPUS)
static inline int __first_cpu(const cpumask_t *srcp, int nbits)
{
- return find_first_bit(srcp->bits, nbits);
+ int cpu = find_first_bit(srcp->bits, nbits);
+ if (cpu > NR_CPUS)
+ cpu = NR_CPUS;
+ return cpu;
}

#define next_cpu(n, src) __next_cpu((n), &(src), NR_CPUS)
static inline int __next_cpu(int n, const cpumask_t *srcp, int nbits)
{
- return find_next_bit(srcp->bits, nbits, n+1);
+ int cpu = find_next_bit(srcp->bits, nbits, n+1);
+ if (cpu > NR_CPUS)
+ cpu = NR_CPUS;
+ return cpu;
}

#define cpumask_of_cpu(cpu) \
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/