[PATCH v2] nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn()
mwilck at suse.com
mwilck at suse.com
Mon Feb 1 19:59:51 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 | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f320273fc672..8b0fc4a07b31 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3538,8 +3538,14 @@ static ssize_t nvme_sysfs_show_subsysnqn(struct device *dev,
char *buf)
{
struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+ char *subsysnqn = "unknown";
- 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;
+
+ 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