@@ -149,7 +149,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 (hint && wrap) {
+ if (wrap) {
+ wrap = false;
hint = 0;
continue;
}
@@ -160,8 +161,14 @@ static int __sbitmap_get_word(unsigned long *word, unsigned long depth,
break;
hint = nr + 1;
- if (hint >= depth - 1)
- hint = 0;
+ if (unlikely(hint >= depth)) {
+ if (wrap) {
+ wrap = false;
+ hint = 0;
+ continue;
+ }
+ return -1;
+ }
}
return nr;