Reduce rbtree boiler plate by using the new helpers.
Showing the changes to lib/timerqueue.c (1 of 1 file). Show all
Unified · Split
| @@ -14,6 +14,14 @@ · 13 unmodified lines | ||
| 14 | 14 | #include <linux/rbtree.h> |
| 15 | 15 | #include <linux/export.h> |
| 16 | 16 | |
| 17 | +#define __node_2_tq(_n) \ | |
| 18 | + rb_entry((_n), struct timerqueue_node, node) | |
| 19 | + | |
| 20 | +static inline bool __timerqueue_less(struct rb_node *a, const struct rb_node *b) | |
| 21 | +{ | |
| 22 | + return __node_2_tq(a)->expires < __node_2_tq(b)->expires; | |
| 23 | +} | |
| 24 | + | |
| 17 | 25 | /** |
| 18 | 26 | * timerqueue_add - Adds timer to timerqueue. |
| 19 | 27 | * |
| @@ -26,28 +34,10 @@ · 6 unmodified lines | ||
| 26 | 34 | */ |
| 27 | 35 | bool timerqueue_add(struct timerqueue_head *head, struct timerqueue_node *node) |
| 28 | 36 | { |
| 29 | − struct rb_node **p = &head->rb_root.rb_root.rb_node; | |
| 30 | − struct rb_node *parent = NULL; | |
| 31 | − struct timerqueue_node *ptr; | |
| 32 | − bool leftmost = true; | |
| 33 | − | |
| 34 | 37 | /* Make sure we don't add nodes that are already added */ |
| 35 | 38 | WARN_ON_ONCE(!RB_EMPTY_NODE(&node->node)); |
| 36 | 39 | |
| 37 | − while (*p) { | |
| 38 | − parent = *p; | |
| 39 | − ptr = rb_entry(parent, struct timerqueue_node, node); | |
| 40 | − if (node->expires < ptr->expires) { | |
| 41 | − p = &(*p)->rb_left; | |
| 42 | − } else { | |
| 43 | − p = &(*p)->rb_right; | |
| 44 | − leftmost = false; | |
| 45 | − } | |
| 46 | − } | |
| 47 | − rb_link_node(&node->node, parent, p); | |
| 48 | − rb_insert_color_cached(&node->node, &head->rb_root, leftmost); | |
| 49 | − | |
| 50 | − return leftmost; | |
| 40 | + return rb_add_cached(&node->node, &head->rb_root, __timerqueue_less); | |
| 51 | 41 | } |
| 52 | 42 | EXPORT_SYMBOL_GPL(timerqueue_add); |
| 53 | 43 | |