diff options
Diffstat (limited to 'lib/rbtree.c')
-rw-r--r-- | lib/rbtree.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/rbtree.c b/lib/rbtree.c index 12abb8abf442..d0be5fcaafe8 100644 --- a/lib/rbtree.c +++ b/lib/rbtree.c | |||
@@ -91,8 +91,21 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root) | |||
91 | { | 91 | { |
92 | struct rb_node *parent, *gparent; | 92 | struct rb_node *parent, *gparent; |
93 | 93 | ||
94 | while ((parent = rb_parent(node)) && rb_is_red(parent)) | 94 | while (true) { |
95 | { | 95 | /* |
96 | * Loop invariant: node is red | ||
97 | * | ||
98 | * If there is a black parent, we are done. | ||
99 | * Otherwise, take some corrective action as we don't | ||
100 | * want a red root or two consecutive red nodes. | ||
101 | */ | ||
102 | parent = rb_parent(node); | ||
103 | if (!parent) { | ||
104 | rb_set_black(node); | ||
105 | break; | ||
106 | } else if (rb_is_black(parent)) | ||
107 | break; | ||
108 | |||
96 | gparent = rb_parent(parent); | 109 | gparent = rb_parent(parent); |
97 | 110 | ||
98 | if (parent == gparent->rb_left) | 111 | if (parent == gparent->rb_left) |
@@ -142,8 +155,6 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root) | |||
142 | break; | 155 | break; |
143 | } | 156 | } |
144 | } | 157 | } |
145 | |||
146 | rb_set_black(root->rb_node); | ||
147 | } | 158 | } |
148 | EXPORT_SYMBOL(rb_insert_color); | 159 | EXPORT_SYMBOL(rb_insert_color); |
149 | 160 | ||