From patchwork Fri Sep 8 22:25:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9945115 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 20DA260224 for ; Fri, 8 Sep 2017 22:32:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1720528950 for ; Fri, 8 Sep 2017 22:32:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0BBB328953; Fri, 8 Sep 2017 22:32:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A72BA28950 for ; Fri, 8 Sep 2017 22:32:20 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 83AC921E8797A; Fri, 8 Sep 2017 15:29:27 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id ED02421A143F5 for ; Fri, 8 Sep 2017 15:29:26 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Sep 2017 15:32:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,363,1500966000"; d="scan'208"; a="1216509647" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by fmsmga002.fm.intel.com with ESMTP; 08 Sep 2017 15:32:19 -0700 Subject: [ndctl PATCH 1/2] ndctl: reduce indentation in util_region_badblocks_to_json / dev_badblocks_to_json From: Dan Williams To: linux-nvdimm@lists.01.org Date: Fri, 08 Sep 2017 15:25:55 -0700 Message-ID: <150490955511.8621.11056333479696382004.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: y-goto@jp.fujitsu.com Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Use a 'continue' to out-dent the badblock parsing code block. Cc: Dave Jiang Cc: Yasunori Goto Signed-off-by: Dan Williams --- util/json.c | 108 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 57 insertions(+), 51 deletions(-) diff --git a/util/json.c b/util/json.c index 639f0ff043ca..1d1727c1c062 100644 --- a/util/json.c +++ b/util/json.c @@ -389,43 +389,46 @@ struct json_object *util_region_badblocks_to_json(struct ndctl_region *region, } ndctl_region_badblock_foreach(region, bb) { - if (flags & UTIL_JSON_MEDIA_ERRORS) { - struct ndctl_dimm *dimm = NULL; - unsigned long long spa; + struct ndctl_dimm *dimm; + unsigned long long addr; + const char *devname; - /* get start address of region */ - spa = ndctl_region_get_resource(region); - if (spa == ULONG_MAX) - goto err_array; + bbs += bb->len; - /* get address of bad block */ - spa += bb->offset << 9; - dimm = badblock_to_dimm(region, spa); + if (!(flags & UTIL_JSON_MEDIA_ERRORS)) + continue; - jbb = json_object_new_object(); - if (!jbb) - goto err_array; + /* get start address of region */ + addr = ndctl_region_get_resource(region); + if (addr == ULONG_MAX) + goto err_array; - jobj = json_object_new_int64(bb->offset); - if (!jobj) - goto err; - json_object_object_add(jbb, "offset", jobj); + /* get address of bad block */ + addr += bb->offset << 9; + dimm = badblock_to_dimm(region, addr); + + jbb = json_object_new_object(); + if (!jbb) + goto err_array; + + jobj = json_object_new_int64(bb->offset); + if (!jobj) + goto err; + json_object_object_add(jbb, "offset", jobj); + + jobj = json_object_new_int(bb->len); + if (!jobj) + goto err; + json_object_object_add(jbb, "length", jobj); - jobj = json_object_new_int(bb->len); + if (dimm) { + devname = ndctl_dimm_get_devname(dimm); + jobj = json_object_new_string(devname); if (!jobj) goto err; - json_object_object_add(jbb, "length", jobj); - - if (dimm) { - jobj = json_object_new_string(ndctl_dimm_get_devname(dimm)); - if (!jobj) - goto err; - json_object_object_add(jbb, "dimm", jobj); - } - json_object_array_add(jbbs, jbb); + json_object_object_add(jbb, "dimm", jobj); } - - bbs += bb->len; + json_object_array_add(jbbs, jbb); } *bb_count = bbs; @@ -463,7 +466,8 @@ static struct json_object *dev_badblocks_to_json(struct ndctl_region *region, ndctl_region_badblock_foreach(region, bb) { unsigned long long bb_begin, bb_end, begin, end; - struct ndctl_dimm *dimm = NULL; + struct ndctl_dimm *dimm; + const char *devname; bb_begin = region_begin + (bb->offset << 9); bb_end = bb_begin + (bb->len << 9) - 1; @@ -486,32 +490,34 @@ static struct json_object *dev_badblocks_to_json(struct ndctl_region *region, dimm = badblock_to_dimm(region, begin); - if (flags & UTIL_JSON_MEDIA_ERRORS) { - /* add to json */ - jbb = json_object_new_object(); - if (!jbb) - goto err_array; + bbs += len; + + if (!(flags & UTIL_JSON_MEDIA_ERRORS)) + continue; - jobj = json_object_new_int64(offset); - if (!jobj) - goto err; - json_object_object_add(jbb, "offset", jobj); + jbb = json_object_new_object(); + if (!jbb) + goto err_array; - jobj = json_object_new_int(len); - if (!jobj) - goto err; - json_object_object_add(jbb, "length", jobj); + jobj = json_object_new_int64(offset); + if (!jobj) + goto err; + json_object_object_add(jbb, "offset", jobj); - if (dimm) { - jobj = json_object_new_string(ndctl_dimm_get_devname(dimm)); - if (!jobj) - goto err; - json_object_object_add(jbb, "dimm", jobj); - } + jobj = json_object_new_int(len); + if (!jobj) + goto err; + json_object_object_add(jbb, "length", jobj); - json_object_array_add(jbbs, jbb); + if (dimm) { + devname = ndctl_dimm_get_devname(dimm); + jobj = json_object_new_string(devname); + if (!jobj) + goto err; + json_object_object_add(jbb, "dimm", jobj); } - bbs += len; + + json_object_array_add(jbbs, jbb); } *bb_count = bbs;