diff options
author | Pavel Begunkov <asml.silence@gmail.com> | 2020-11-22 18:35:48 +0300 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2020-12-08 03:12:49 +0300 |
commit | 0eff1f1a38a95b20fec83d0b69409c8da967fe1e (patch) | |
tree | c1a9098927f94bc63dd67b111275a56bf21606ed /lib/sbitmap.c | |
parent | c3250c8d2451ffbea14ba95164c59edd943ee4be (diff) | |
download | linux-0eff1f1a38a95b20fec83d0b69409c8da967fe1e.tar.xz |
sbitmap: simplify wrap check
__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>
Diffstat (limited to 'lib/sbitmap.c')
-rw-r--r-- | lib/sbitmap.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/sbitmap.c b/lib/sbitmap.c index c18b518a16ba..d693d9213ceb 100644 --- a/lib/sbitmap.c +++ b/lib/sbitmap.c @@ -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)) { @@ -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; |