Whamcloud - gitweb
LU-4702 nodemap: fix nm_rbtree_postorder_for_each_entry_safe() 00/9500/2
authorNiu Yawei <yawei.niu@intel.com>
Wed, 5 Mar 2014 12:17:39 +0000 (07:17 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 10 Mar 2014 23:38:37 +0000 (23:38 +0000)
It should check if the 'pos' && 'n' is NULL.

Signed-off-by: Niu Yawei <yawei.niu@intel.com>
Change-Id: Ibda34ec4cf1706f0651ed8c86a2e49e4a36cd2c0
Reviewed-on: http://review.whamcloud.com/9500
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Joshua Walgenbach <jjw@iu.edu>
lustre/nodemap/nodemap_internal.h

index af3836e..7751177 100644 (file)
@@ -96,12 +96,15 @@ struct rb_node *nm_rb_first_postorder(const struct rb_root *root);
 
 #define nm_rbtree_postorder_for_each_entry_safe(pos, n,                        \
                                                root, field)            \
-       for (pos = rb_entry(nm_rb_first_postorder(root), typeof(*pos),  \
-                           field),                                     \
-               n = rb_entry(nm_rb_next_postorder(&pos->field),         \
-               typeof(*pos), field);                                   \
-               &pos->field;                                            \
+       for (pos = nm_rb_first_postorder(root) ?                        \
+               rb_entry(nm_rb_first_postorder(root), typeof(*pos),     \
+               field) : NULL,                                          \
+               n = (pos && nm_rb_next_postorder(&pos->field)) ?        \
+               rb_entry(nm_rb_next_postorder(&pos->field),             \
+               typeof(*pos), field) : NULL;                            \
+               pos != NULL;                                            \
                pos = n,                                                \
-               n = rb_entry(nm_rb_next_postorder(&pos->field),         \
-                            typeof(*pos), field))
+               n = (pos && nm_rb_next_postorder(&pos->field)) ?        \
+               rb_entry(nm_rb_next_postorder(&pos->field),             \
+               typeof(*pos), field) : NULL)
 #endif  /* _NODEMAP_INTERNAL_H */