Message ID | 20170803211835.18988-1-vishal.l.verma@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Thu, Aug 3, 2017 at 2:18 PM, Vishal Verma <vishal.l.verma@intel.com> wrote: > 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> Looks good to me, applied.
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;
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(-)