find_next_bit() and find_next_zero_bit(): if the caller-specified offset

lies within the last block of the bit set and no bits are set beyond the
offset, terminate the search immediately instead of continuing as though
there are further blocks in the set and subsequently returning an incorrect
result.

MFC after:	1 week
Sponsored by:	EMC / Isilon Storage Division
This commit is contained in:
Mark Johnston 2015-05-10 22:04:42 +00:00
parent 28a6bc8146
commit 979b8eaf4b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=282741

View File

@ -165,6 +165,8 @@ find_next_bit(unsigned long *addr, unsigned long size, unsigned long offset)
mask = (*addr) & ~BIT_MASK(offs);
if (mask)
return (bit + __ffsl(mask));
if (size - bit <= BITS_PER_LONG)
return (size);
bit += BITS_PER_LONG;
addr++;
}
@ -203,6 +205,8 @@ find_next_zero_bit(unsigned long *addr, unsigned long size,
mask = ~(*addr) & ~BIT_MASK(offs);
if (mask)
return (bit + __ffsl(mask));
if (size - bit <= BITS_PER_LONG)
return (size);
bit += BITS_PER_LONG;
addr++;
}