From patchwork Fri Sep 29 00:47:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9976953 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 825DE60365 for ; Fri, 29 Sep 2017 00:54:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DAC127CEA for ; Fri, 29 Sep 2017 00:54:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6089327F8F; Fri, 29 Sep 2017 00:54:15 +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 EA08E27CEA for ; Fri, 29 Sep 2017 00:54:14 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1E6F32095E516; Thu, 28 Sep 2017 17:50:59 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 1BDA320945BD6 for ; Thu, 28 Sep 2017 17:50:57 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Sep 2017 17:54:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,451,1500966000"; d="scan'208";a="317495314" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by fmsmga004.fm.intel.com with ESMTP; 28 Sep 2017 17:54:12 -0700 Subject: [ndctl PATCH] ndctl, list: fix crash when listing idle device-dax instances From: Dan Williams To: linux-nvdimm@lists.01.org Date: Thu, 28 Sep 2017 17:47:48 -0700 Message-ID: <150664606831.15244.13043658016858646915.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: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- util/json.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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);