[PATCH] nvme-core: warn and abort if shared ns with empty list
Irvin Cote
irvincoteg at gmail.com
Tue Jun 6 01:21:34 PDT 2023
In nvme_find_ns_head if we find a shared ns but it has an empty
list or its refcount is 0 we gloss over it and go to the next.
Ignoring when such a case happens means that when nvme_find_ns_head
returns NULL, we could create a new nshead with the same nsid. Hence
we could find ourselves with two shared nsheads having the same nsid.
Instead warn the user through dev_err and exit.
Signed-off-by: Irvin Cote <irvincoteg at gmail.com>
---
drivers/nvme/host/core.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index c8a471482421..175f1516083f 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3341,6 +3341,11 @@ static struct nvme_ns_head *nvme_find_ns_head(struct nvme_ctrl *ctrl,
continue;
if (!list_empty(&h->list) && nvme_tryget_ns_head(h))
return h;
+ else {
+ dev_err(ctrl->device,
+ "Found shared namespace with empty list or 0 refcount\n");
+ return ERR_PTR(-ENOENT);
+ }
}
return NULL;
@@ -3535,6 +3540,12 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
mutex_lock(&ctrl->subsys->lock);
head = nvme_find_ns_head(ctrl, info->nsid);
+
+ if (IS_ERR(head)) {
+ ret = PTR_ERR(head);
+ goto out_unlock;
+ }
+
if (!head) {
ret = nvme_subsys_check_duplicate_ids(ctrl->subsys, &info->ids);
if (ret) {
--
2.40.1
More information about the Linux-nvme
mailing list