Skip to contentSkip to conversation

kvmtool: devices.c: Update parent when inserting into rbtree

PATCH New James Morse 1 participant 1 message Jun 15, 2016

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

PATCH 1/1 kvmtool: devices.c: Update parent when inserting into rbtree

When walking the devices rbtree to insert a node, we must keep track of the parent node when we descend. If we skip this step, we always insert new nodes with a NULL parent, bypassing __rb_insert()s rebalance code.

Things get worse when we come to walk the tree, as we can't move up a level. This isn't a problem in practice, as all devices appear to be inserted in-order, so our rbtree is actually a monochrome linked list.

---
 devices.c | 1 +
 1 file changed, 1 insertion(+)
devices.c +1 -0
index b560a59..a7c666a 100644
@@ -45,6 +45,7 @@ int device__register(struct device_header *dev)
 		int num = rb_entry(*node, struct device_header, node)->dev_num;
 		int result = dev->dev_num - num;
 
+		parent = *node;
 		if (result < 0)
 			node = &((*node)->rb_left);
 		else if (result > 0)
Signature · 1 line
2.8.0.rc3