Add find_next_zero_string to lib/ and bitops.h Used to be x86-64 specific before it was removed. Readding it as generic code because I need it for future patches. This version assumes that most searches are for only a single bit; it doesn't try to be particularly efficient for multiple bits (but is also not too bad either) Signed-off-by: Andi Kleen Signed-off-by: Andi Kleen --- include/linux/bitops.h | 3 +++ lib/Makefile | 2 +- lib/bitstr.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) Index: linux/include/linux/bitops.h =================================================================== --- linux.orig/include/linux/bitops.h +++ linux/include/linux/bitops.h @@ -72,4 +72,7 @@ static inline unsigned fls_long(unsigned return fls64(l); } +extern unsigned long find_next_zero_string(unsigned long *bitmap, + long start, long nbits, int len); + #endif Index: linux/lib/bitstr.c =================================================================== --- /dev/null +++ linux/lib/bitstr.c @@ -0,0 +1,27 @@ +#include +#include + +/* Find string of zero bits in a bitmap */ +unsigned long +find_next_zero_string(unsigned long *bitmap, long start, long nbits, int len) +{ + unsigned long n, end, i; + + again: + n = find_next_zero_bit(bitmap, nbits, start); + if (n == -1) + return -1; + + /* could test bitsliced, but it's hardly worth it */ + end = n+len; + if (end >= nbits) + return -1; + for (i = n+1; i < end; i++) { + if (test_bit(i, bitmap)) { + start = i+1; + goto again; + } + } + return n; +} +EXPORT_SYMBOL(find_next_zero_string); Index: linux/lib/Makefile =================================================================== --- linux.orig/lib/Makefile +++ linux/lib/Makefile @@ -6,7 +6,7 @@ lib-y := ctype.o string.o vsprintf.o cmd rbtree.o radix-tree.o dump_stack.o \ idr.o int_sqrt.o extable.o prio_tree.o \ sha1.o irq_regs.o reciprocal_div.o argv_split.o \ - proportions.o prio_heap.o + proportions.o prio_heap.o bitstr.o lib-$(CONFIG_MMU) += ioremap.o lib-$(CONFIG_SMP) += cpumask.o