diff mbox

[01/11] ndctl: fix ndctl_{namespace|btt}_foreach_safe

Message ID 20151015210549.22046.32346.stgit@dwillia2-desk3.jf.intel.com (mailing list archive)
State Accepted
Commit 377c2cc0dece
Headers show

Commit Message

Dan Williams Oct. 15, 2015, 9:05 p.m. UTC
Static analysis points out that we are potentially passing NULL to
ndctl_{namespace|btt}_get_next() in these macros.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 lib/ndctl/libndctl.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/lib/ndctl/libndctl.h b/lib/ndctl/libndctl.h
index d36a86afa1a6..3ccffa9093b9 100644
--- a/lib/ndctl/libndctl.h
+++ b/lib/ndctl/libndctl.h
@@ -269,7 +269,7 @@  struct ndctl_namespace *ndctl_namespace_get_next(struct ndctl_namespace *ndns);
              ndns = ndctl_namespace_get_next(ndns))
 #define ndctl_namespace_foreach_safe(region, ndns, _ndns) \
 	for (ndns = ndctl_namespace_get_first(region), \
-	     _ndns = ndctl_namespace_get_next(ndns); \
+	     _ndns = ndns ? ndctl_namespace_get_next(ndns) : NULL; \
 	     ndns != NULL; \
 	     ndns = _ndns, \
 	     _ndns = _ndns ? ndctl_namespace_get_next(_ndns) : NULL)
@@ -315,7 +315,7 @@  struct ndctl_btt *ndctl_btt_get_next(struct ndctl_btt *btt);
              btt = ndctl_btt_get_next(btt))
 #define ndctl_btt_foreach_safe(region, btt, _btt) \
 	for (btt = ndctl_btt_get_first(region), \
-	     _btt = ndctl_btt_get_next(btt); \
+	     _btt = btt ? ndctl_btt_get_next(btt) : NULL; \
 	     btt != NULL; \
 	     btt = _btt, \
 	     _btt = _btt ? ndctl_btt_get_next(_btt) : NULL)