Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] rbtree: fixed reversed RB_EMPTY_NODE and rb_next/prev

The conditions got reserved. Also make rb_next() and rb_prev() check
for the empty condition.

Signed-off-by: Jens Axboe <axboe@suse.de>

authored by

Jens Axboe and committed by
Jens Axboe
10fd48f2 9817064b

+9 -3
+2 -2
block/as-iosched.c
··· 336 336 337 337 static inline void as_del_arq_rb(struct as_data *ad, struct as_rq *arq) 338 338 { 339 - if (!RB_EMPTY_NODE(&arq->rb_node)) { 339 + if (RB_EMPTY_NODE(&arq->rb_node)) { 340 340 WARN_ON(1); 341 341 return; 342 342 } ··· 1039 1039 struct request *rq = arq->request; 1040 1040 const int data_dir = arq->is_sync; 1041 1041 1042 - BUG_ON(!RB_EMPTY_NODE(&arq->rb_node)); 1042 + BUG_ON(RB_EMPTY_NODE(&arq->rb_node)); 1043 1043 1044 1044 as_antic_stop(ad); 1045 1045 ad->antic_status = ANTIC_OFF;
+1 -1
include/linux/rbtree.h
··· 133 133 #define rb_entry(ptr, type, member) container_of(ptr, type, member) 134 134 135 135 #define RB_EMPTY_ROOT(root) ((root)->rb_node == NULL) 136 - #define RB_EMPTY_NODE(node) (rb_parent(node) != node) 136 + #define RB_EMPTY_NODE(node) (rb_parent(node) == node) 137 137 #define RB_CLEAR_NODE(node) (rb_set_parent(node, node)) 138 138 139 139 extern void rb_insert_color(struct rb_node *, struct rb_root *);
+6
lib/rbtree.c
··· 322 322 { 323 323 struct rb_node *parent; 324 324 325 + if (rb_parent(node) == node) 326 + return NULL; 327 + 325 328 /* If we have a right-hand child, go down and then left as far 326 329 as we can. */ 327 330 if (node->rb_right) { ··· 350 347 struct rb_node *rb_prev(struct rb_node *node) 351 348 { 352 349 struct rb_node *parent; 350 + 351 + if (rb_parent(node) == node) 352 + return NULL; 353 353 354 354 /* If we have a left-hand child, go down and then right as far 355 355 as we can. */