All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vishal Verma <vishal.l.verma@intel.com>
To: linux-nvdimm@lists.01.org
Subject: [PATCH] ndctl, util: in util_namespace_to_json, initialize bb_count to 0
Date: Thu,  3 Aug 2017 15:18:35 -0600	[thread overview]
Message-ID: <20170803211835.18988-1-vishal.l.verma@intel.com> (raw)

If in the util_namespace_to_json -> dev_badblocks_to_json call chain, if
anything errors out before setting bb_count, bb_count will have an
uninitialized, random value.

This happens during namespace creation, as the namespaceX.Y/resource is
not available (as the namespace is disabled), and the various
util_<mode>_badblocks_to_json helpers fail due to a missing resource.

$ ndctl create-namespace --type=pmem --mode=sector
{
  "dev":"namespace7.0",
  "mode":"sector",
  "size":"62.91 MiB (65.97 MB)",
  "uuid":"ca26fe8e-3f9a-4e3f-bfb0-1e34714996a4",
  "sector_size":4096,
  "blockdev":"pmem7s",
  "badblock_count":22
}

$ ndctl list --namespace=namespace7.0
{
  "dev":"namespace7.0",
  "mode":"sector",
  "size":65966080,
  "uuid":"ca26fe8e-3f9a-4e3f-bfb0-1e34714996a4",
  "sector_size":4096,
  "blockdev":"pmem7s",
  "badblock_count":8
}

Fix this by initializing bb_count to 0.

Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 util/json.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/json.c b/util/json.c
index 80512bd..59bd272 100644
--- a/util/json.c
+++ b/util/json.c
@@ -541,7 +541,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
 	unsigned long long size = ULLONG_MAX;
 	enum ndctl_namespace_mode mode;
 	const char *bdev = NULL;
-	unsigned int bb_count;
+	unsigned int bb_count = 0;
 	struct ndctl_btt *btt;
 	struct ndctl_pfn *pfn;
 	struct ndctl_dax *dax;
-- 
2.9.3

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

             reply	other threads:[~2017-08-03 21:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-03 21:18 Vishal Verma [this message]
2017-08-03 22:27 ` [PATCH] ndctl, util: in util_namespace_to_json, initialize bb_count to 0 Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170803211835.18988-1-vishal.l.verma@intel.com \
    --to=vishal.l.verma@intel.com \
    --cc=linux-nvdimm@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.