Skip to content

Commit

Permalink
lib/idr.c: Fix bug introduced by RCU fix
Browse files Browse the repository at this point in the history
The last patch to lib/idr.c caused a bug if idr_get_new_above() was
called on an empty idr.

Usually, nodes stay on the same layer.  New layers are added to the top
of the tree.

The exception is idr_get_new_above() on an empty tree: In this case, the
new root node is first added on layer 0, then moved upwards.  p->layer
was not updated.

As usual: You shall never rely on the source code comments, they will
only mislead you.

Signed-off-by: Manfred Spraul <manfred@colorfullife.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
manfred-colorfu authored and torvalds committed Dec 10, 2008
1 parent c7f8d6f commit 711a49a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/idr.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,14 @@ static int idr_get_empty_slot(struct idr *idp, int starting_id,
*/
while ((layers < (MAX_LEVEL - 1)) && (id >= (1 << (layers*IDR_BITS)))) {
layers++;
if (!p->count)
if (!p->count) {
/* special case: if the tree is currently empty,
* then we grow the tree by moving the top node
* upwards.
*/
p->layer++;
continue;
}
if (!(new = get_from_free_list(idp))) {
/*
* The allocation failed. If we built part of
Expand Down

0 comments on commit 711a49a

Please sign in to comment.