Skip to content

Commit

Permalink
[PATCH] rbtree: fixed reversed RB_EMPTY_NODE and rb_next/prev
Browse files Browse the repository at this point in the history
The conditions got reserved. Also make rb_next() and rb_prev() check
for the empty condition.

Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Jens Axboe authored and Jens Axboe committed Sep 30, 2006
1 parent 9817064 commit 10fd48f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions block/as-iosched.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ static void as_add_arq_rb(struct as_data *ad, struct as_rq *arq)

static inline void as_del_arq_rb(struct as_data *ad, struct as_rq *arq)
{
if (!RB_EMPTY_NODE(&arq->rb_node)) {
if (RB_EMPTY_NODE(&arq->rb_node)) {
WARN_ON(1);
return;
}
Expand Down Expand Up @@ -1039,7 +1039,7 @@ static void as_move_to_dispatch(struct as_data *ad, struct as_rq *arq)
struct request *rq = arq->request;
const int data_dir = arq->is_sync;

BUG_ON(!RB_EMPTY_NODE(&arq->rb_node));
BUG_ON(RB_EMPTY_NODE(&arq->rb_node));

as_antic_stop(ad);
ad->antic_status = ANTIC_OFF;
Expand Down
2 changes: 1 addition & 1 deletion include/linux/rbtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static inline void rb_set_color(struct rb_node *rb, int color)
#define rb_entry(ptr, type, member) container_of(ptr, type, member)

#define RB_EMPTY_ROOT(root) ((root)->rb_node == NULL)
#define RB_EMPTY_NODE(node) (rb_parent(node) != node)
#define RB_EMPTY_NODE(node) (rb_parent(node) == node)
#define RB_CLEAR_NODE(node) (rb_set_parent(node, node))

extern void rb_insert_color(struct rb_node *, struct rb_root *);
Expand Down
6 changes: 6 additions & 0 deletions lib/rbtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ struct rb_node *rb_next(struct rb_node *node)
{
struct rb_node *parent;

if (rb_parent(node) == node)
return NULL;

/* If we have a right-hand child, go down and then left as far
as we can. */
if (node->rb_right) {
Expand All @@ -348,6 +351,9 @@ struct rb_node *rb_prev(struct rb_node *node)
{
struct rb_node *parent;

if (rb_parent(node) == node)
return NULL;

/* If we have a left-hand child, go down and then right as far
as we can. */
if (node->rb_left) {
Expand Down

0 comments on commit 10fd48f

Please sign in to comment.