diff mbox

[ndctl] ndctl, list: fix crash when listing idle device-dax instances

Message ID 150664606831.15244.13043658016858646915.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State Accepted
Commit 4a934b716888
Headers show

Commit Message

Dan Williams Sept. 29, 2017, 12:47 a.m. UTC
The following crash results from running 'ndctl list -i' on an inactive
namespace that is claimed for device-dax operation.

    Program received signal SIGSEGV, Segmentation fault.
    daxctl_dev_get_devname (dev=0x0) at libdaxctl.c:566
    566             return devpath_to_devname(dev->dev_path);
    (gdb) bt
    #0  daxctl_dev_get_devname (dev=0x0) at libdaxctl.c:566
    #1  0x0000555555563b39 in util_namespace_to_json
        at ../util/json.c:751

By definition the 'chardev' attribute for a device-dax instance can not
be found if the device-dax instance is disabled, because enabling the
namespace creates the child character device(s).

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 util/json.c |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/util/json.c b/util/json.c
index dac8692a89af..d1ee351546b9 100644
--- a/util/json.c
+++ b/util/json.c
@@ -747,12 +747,18 @@  struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
 		} else if (dax_region) {
 			struct daxctl_dev *dev;
 
+			/*
+			 * We can only find/list these device-dax
+			 * details when the instance is enabled.
+			 */
 			dev = daxctl_dev_get_first(dax_region);
-			name = daxctl_dev_get_devname(dev);
-			jobj = json_object_new_string(name);
-			if (!jobj)
-				goto err;
-			json_object_object_add(jndns, "chardev", jobj);
+			if (dev) {
+				name = daxctl_dev_get_devname(dev);
+				jobj = json_object_new_string(name);
+				if (!jobj)
+					goto err;
+				json_object_object_add(jndns, "chardev", jobj);
+			}
 		}
 	} else if (ndctl_namespace_get_type(ndns) != ND_DEVICE_NAMESPACE_IO) {
 		ndctl_namespace_get_uuid(ndns, uuid);