From: Niu Yawei Date: Wed, 5 Mar 2014 12:17:39 +0000 (-0500) Subject: LU-4702 nodemap: fix nm_rbtree_postorder_for_each_entry_safe() X-Git-Tag: 2.5.57~23 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=155031eeacbb4b79fec7cc2a811afcba9fb39d7a LU-4702 nodemap: fix nm_rbtree_postorder_for_each_entry_safe() It should check if the 'pos' && 'n' is NULL. Signed-off-by: Niu Yawei Change-Id: Ibda34ec4cf1706f0651ed8c86a2e49e4a36cd2c0 Reviewed-on: http://review.whamcloud.com/9500 Tested-by: Jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Joshua Walgenbach --- diff --git a/lustre/nodemap/nodemap_internal.h b/lustre/nodemap/nodemap_internal.h index af3836e..7751177 100644 --- a/lustre/nodemap/nodemap_internal.h +++ b/lustre/nodemap/nodemap_internal.h @@ -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 */