Skip to content

Commit

Permalink
idr: fix a subtle bug in idr_get_next()
Browse files Browse the repository at this point in the history
  • Loading branch information
javilonas committed May 29, 2015
1 parent bee6482 commit 303e2e5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/idr.c
Expand Up @@ -738,7 +738,14 @@ int idr_for_each(struct idr *idp,
break;
}

id += 1 << n;
/*
* Proceed to the next layer at the current level. Unlike
* idr_for_each(), @id isn't guaranteed to be aligned to
* layer boundary at this point and adding 1 << n may
* incorrectly skip IDs. Make sure we jump to the
* beginning of the next layer using round_up().
*/
id = round_up(id + 1, 1 << n);
while (n < fls(id)) {
n += IDR_BITS;
p = *--paa;
Expand Down

0 comments on commit 303e2e5

Please sign in to comment.