]> git.hungrycats.org Git - linux/commitdiff
[PATCH] first/next_cpu returns values > NR_CPUS
authorWilliam Lee Irwin III <wli@holomorphy.com>
Tue, 24 Aug 2004 04:20:21 +0000 (21:20 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Tue, 24 Aug 2004 04:20:21 +0000 (21:20 -0700)
Zwane Mwaikambo <zwane@fsmlabs.com> wrote:

  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.

This might save a couple of lines of code.

From: <akpm@osdl.org>

  Fix cross-arch ulong/int disaster with find_next_bit().

Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
include/linux/cpumask.h

index 7109aa6e501efa2e045b58fb01b42f81d89dc645..1ff1e85f6e59496d38907f0fb7c992d9a3da5314 100644 (file)
@@ -73,6 +73,7 @@
  *    inside a macro, the way we do the other calls.
  */
 
+#include <linux/kernel.h>
 #include <linux/threads.h>
 #include <linux/bitmap.h>
 #include <asm/bug.h>
@@ -207,13 +208,13 @@ static inline void __cpus_shift_left(cpumask_t *dstp,
 #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);
+       return min_t(int, nbits, find_first_bit(srcp->bits, nbits));
 }
 
 #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);
+       return min_t(int, nbits, find_next_bit(srcp->bits, nbits, n+1));
 }
 
 #define cpumask_of_cpu(cpu)                                            \