We don't need to check for the above flag for each badblock we're
iterating over. Remove the check in the respective loops, and return
early if it is not set.

Cc: Dan Williams <[email protected]>
Signed-off-by: Vishal Verma <[email protected]>
---
 util/json.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/util/json.c b/util/json.c
index 30b56c3..4dd5fc3 100644
--- a/util/json.c
+++ b/util/json.c
@@ -457,7 +457,8 @@ struct json_object *util_region_badblocks_to_json(struct 
ndctl_region *region,
                jbbs = json_object_new_array();
                if (!jbbs)
                        return NULL;
-       }
+       } else
+               return NULL;
 
        ndctl_region_badblock_foreach(region, bb) {
                struct json_object *jdimms;
@@ -465,9 +466,6 @@ struct json_object *util_region_badblocks_to_json(struct 
ndctl_region *region,
 
                bbs += bb->len;
 
-               if (!(flags & UTIL_JSON_MEDIA_ERRORS))
-                       continue;
-
                /* get start address of region */
                addr = ndctl_region_get_resource(region);
                if (addr == ULLONG_MAX)
@@ -527,7 +525,8 @@ static struct json_object *dev_badblocks_to_json(struct 
ndctl_region *region,
                jbbs = json_object_new_array();
                if (!jbbs)
                        return NULL;
-       }
+       } else
+               return NULL;
 
        ndctl_region_badblock_foreach(region, bb) {
                unsigned long long bb_begin, bb_end, begin, end;
@@ -554,9 +553,6 @@ static struct json_object *dev_badblocks_to_json(struct 
ndctl_region *region,
 
                bbs += len;
 
-               if (!(flags & UTIL_JSON_MEDIA_ERRORS))
-                       continue;
-
                jbb = json_object_new_object();
                if (!jbb)
                        goto err_array;
-- 
2.17.1

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

Reply via email to