[PATCH] nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn()

mwilck at suse.com mwilck at suse.com
Mon Feb 1 17:37:13 EST 2021


From: Martin Wilck <mwilck at suse.com>

While a controller is still connecting, ctrl->subsys is NULL and
thus reading the controller's "subsysnqn" sysfs attribute returns
"(efault)". This happens all the time when user space processes
"add" events for NVMe controller devices.

Fix it by returning the nvmf_ctrl_options' subsysnqn attribute
if ctrl->subsys isn't initialized yet.

Signed-off-by: Martin Wilck <mwilck at suse.com>
---
 drivers/nvme/host/core.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f320273fc672..5d901dd0098b 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3538,8 +3538,16 @@ static ssize_t nvme_sysfs_show_subsysnqn(struct device *dev,
 					 char *buf)
 {
 	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+	char *subsysnqn;
 
-	return snprintf(buf, PAGE_SIZE, "%s\n", ctrl->subsys->subnqn);
+	if (ctrl->subsys)
+		subsysnqn = ctrl->subsys->subnqn;
+	else if (ctrl->opts && ctrl->opts->subsysnqn)
+		subsysnqn = ctrl->opts->subsysnqn;
+	else
+		subsysnqn = "unknown";
+
+	return snprintf(buf, PAGE_SIZE, "%s\n", subsysnqn);
 }
 static DEVICE_ATTR(subsysnqn, S_IRUGO, nvme_sysfs_show_subsysnqn, NULL);
 
-- 
2.29.2




More information about the Linux-nvme mailing list