bitmap: relax find_nth_bit() limitation on return value

The function claims to return the bitmap size, if Nth bit doesn't exist.
This rule is violated in inline case because the fns() that is used
there doesn't know anything about size of the bitmap.

So, relax this requirement to '>= size', and make the outline
implementation a bit cheaper.

All in-tree kernel users of find_nth_bit() are safe against that.

Reported-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Closes: https://lore.kernel.org/all/Zi50cAgR8nZvgLa3@yury-ThinkPad/T/#m6da806a0525e74dcc91f35e5f20766ed4e853e8a
Signed-off-by: Yury Norov <yury.norov@gmail.com>

+4 -4
+1 -1
include/linux/find.h
··· 220 220 * idx = find_first_bit(addr, size); 221 221 * 222 222 * Returns the bit number of the N'th set bit. 223 - * If no such, returns @size. 223 + * If no such, returns >= @size. 224 224 */ 225 225 static inline 226 226 unsigned long find_nth_bit(const unsigned long *addr, unsigned long size, unsigned long n)
+1 -1
lib/find_bit.c
··· 87 87 if (sz % BITS_PER_LONG) \ 88 88 tmp = (FETCH) & BITMAP_LAST_WORD_MASK(sz); \ 89 89 found: \ 90 - sz = min(idx * BITS_PER_LONG + fns(tmp, nr), sz); \ 90 + sz = idx * BITS_PER_LONG + fns(tmp, nr); \ 91 91 out: \ 92 92 sz; \ 93 93 })
+2 -2
lib/test_bitmap.c
··· 244 244 expect_eq_uint(60, find_nth_bit(bmap, 64 * 3, 5)); 245 245 expect_eq_uint(80, find_nth_bit(bmap, 64 * 3, 6)); 246 246 expect_eq_uint(123, find_nth_bit(bmap, 64 * 3, 7)); 247 - expect_eq_uint(64 * 3, find_nth_bit(bmap, 64 * 3, 8)); 247 + expect_eq_uint(0, !!(find_nth_bit(bmap, 64 * 3, 8) < 64 * 3)); 248 248 249 249 expect_eq_uint(10, find_nth_bit(bmap, 64 * 3 - 1, 0)); 250 250 expect_eq_uint(20, find_nth_bit(bmap, 64 * 3 - 1, 1)); ··· 254 254 expect_eq_uint(60, find_nth_bit(bmap, 64 * 3 - 1, 5)); 255 255 expect_eq_uint(80, find_nth_bit(bmap, 64 * 3 - 1, 6)); 256 256 expect_eq_uint(123, find_nth_bit(bmap, 64 * 3 - 1, 7)); 257 - expect_eq_uint(64 * 3 - 1, find_nth_bit(bmap, 64 * 3 - 1, 8)); 257 + expect_eq_uint(0, !!(find_nth_bit(bmap, 64 * 3 - 1, 8) < 64 * 3 - 1)); 258 258 259 259 for_each_set_bit(bit, exp1, EXP1_IN_BITS) { 260 260 b = find_nth_bit(exp1, EXP1_IN_BITS, cnt++);