Skip to contentSkip to conversation

lib/idr.c: Fix bug introduced by RCU fix

PATCH In review Manfred Spraul 3 participants 3 messages Dec 10, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/idr.c: Fix bug introduced by RCU fix

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.

---
 lib/idr.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
lib/idr.c +7 -1
index 7a785a0..1c4f928 100644
@@ -220,8 +220,14 @@ build_up:
 	 */
 	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
Signature · 1 line
1.5.6.5
#1 lore raw
Quoted 9 lines · Manfred Spraul

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.

Quoted 4 lines

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

Dave Airlie - can you get this tested and acked with the people who saw this problem with DRI?

Linus

Tested-by on v1 1/1
#2 lore raw
In reply to Manfred Spraul
Quoted 8 lines · Manfred Spraul

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.

Quoted 4 lines

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

I've given this a run on my dri system and it appears to work great.

Quoted 28 lines
---
 lib/idr.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
lib/idr.c +7 -2
index 7a785a0..1c4f928 100644
@@ -220,8 +220,14 @@ build_up:
        */
       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
--

1.5.6.5