diff options
Diffstat (limited to 'include/linux/rbtree.h')
-rw-r--r-- | include/linux/rbtree.h | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h index aa870a4ddf54..57e75ae9910f 100644 --- a/include/linux/rbtree.h +++ b/include/linux/rbtree.h | |||
@@ -85,6 +85,11 @@ static inline void rb_link_node(struct rb_node * node, struct rb_node * parent, | |||
85 | *rb_link = node; | 85 | *rb_link = node; |
86 | } | 86 | } |
87 | 87 | ||
88 | #define rb_entry_safe(ptr, type, member) \ | ||
89 | ({ typeof(ptr) ____ptr = (ptr); \ | ||
90 | ____ptr ? rb_entry(____ptr, type, member) : NULL; \ | ||
91 | }) | ||
92 | |||
88 | /** | 93 | /** |
89 | * rbtree_postorder_for_each_entry_safe - iterate over rb_root in post order of | 94 | * rbtree_postorder_for_each_entry_safe - iterate over rb_root in post order of |
90 | * given type safe against removal of rb_node entry | 95 | * given type safe against removal of rb_node entry |
@@ -95,12 +100,9 @@ static inline void rb_link_node(struct rb_node * node, struct rb_node * parent, | |||
95 | * @field: the name of the rb_node field within 'type'. | 100 | * @field: the name of the rb_node field within 'type'. |
96 | */ | 101 | */ |
97 | #define rbtree_postorder_for_each_entry_safe(pos, n, root, field) \ | 102 | #define rbtree_postorder_for_each_entry_safe(pos, n, root, field) \ |
98 | for (pos = rb_entry(rb_first_postorder(root), typeof(*pos), field),\ | 103 | for (pos = rb_entry_safe(rb_first_postorder(root), typeof(*pos), field); \ |
99 | n = rb_entry(rb_next_postorder(&pos->field), \ | 104 | pos && ({ n = rb_entry_safe(rb_next_postorder(&pos->field), \ |
100 | typeof(*pos), field); \ | 105 | typeof(*pos), field); 1; }); \ |
101 | &pos->field; \ | 106 | pos = n) |
102 | pos = n, \ | ||
103 | n = rb_entry(rb_next_postorder(&pos->field), \ | ||
104 | typeof(*pos), field)) | ||
105 | 107 | ||
106 | #endif /* _LINUX_RBTREE_H */ | 108 | #endif /* _LINUX_RBTREE_H */ |