
From: William Lee Irwin III <wli@holomorphy.com>

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.
DESC
first-next_cpu-returns-values-nr_cpus fix
EDESC

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

Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/include/linux/cpumask.h |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff -puN include/linux/cpumask.h~first-next_cpu-returns-values-nr_cpus include/linux/cpumask.h
--- 25/include/linux/cpumask.h~first-next_cpu-returns-values-nr_cpus	Mon Aug 16 16:20:44 2004
+++ 25-akpm/include/linux/cpumask.h	Mon Aug 16 16:20:49 2004
@@ -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(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);
+	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)						\
_
