Skip to content

Commit

Permalink
sbitmap: simplify wrap check
Browse files Browse the repository at this point in the history
__sbitmap_get_word() doesn't warp if it's starting from the beginning
(i.e. initial hint is 0). Instead of stashing the original hint just set
@wrap accordingly.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Pavel Begunkov authored and Jens Axboe committed Dec 8, 2020
1 parent c3250c8 commit 0eff1f1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/sbitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ EXPORT_SYMBOL_GPL(sbitmap_resize);
static int __sbitmap_get_word(unsigned long *word, unsigned long depth,
unsigned int hint, bool wrap)
{
unsigned int orig_hint = hint;
int nr;

/* don't wrap if starting from 0 */
wrap = wrap && hint;

while (1) {
nr = find_next_zero_bit(word, depth, hint);
if (unlikely(nr >= depth)) {
Expand All @@ -108,8 +110,8 @@ static int __sbitmap_get_word(unsigned long *word, unsigned long depth,
* offset to 0 in a failure case, so start from 0 to
* exhaust the map.
*/
if (orig_hint && hint && wrap) {
hint = orig_hint = 0;
if (hint && wrap) {
hint = 0;
continue;
}
return -1;
Expand Down

0 comments on commit 0eff1f1

Please sign in to comment.