anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone
Blob Blame History Raw
ndctl, list: fix crash when listing idle device-dax instances

BZ: 

commit 4a934b716888d116895e96b0a48a6f5a562cedd0
Author: Dan Williams <dan.j.williams@intel.com>
Date:   Thu Sep 28 15:40:54 2017 -0700

    ndctl, list: fix crash when listing idle device-dax instances
    
    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>

diff --git a/util/json.c b/util/json.c
index dac8692..d1ee351 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);