Commit 6623c5b3 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

nvme: clean up error handling in nvme_init_ns_head

Use a common label for putting the nshead if needed and only convert
nvme status codes for the one case where it actually is needed.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarKeith Busch <kbusch@kernel.org>
Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 3add1d93
...@@ -3501,8 +3501,11 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid, ...@@ -3501,8 +3501,11 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid,
int ret = 0; int ret = 0;
ret = nvme_report_ns_ids(ctrl, nsid, id, &ids); ret = nvme_report_ns_ids(ctrl, nsid, id, &ids);
if (ret) if (ret) {
goto out; if (ret < 0)
return ret;
return blk_status_to_errno(nvme_error_status(ret));
}
mutex_lock(&ctrl->subsys->lock); mutex_lock(&ctrl->subsys->lock);
head = nvme_find_ns_head(ctrl->subsys, nsid); head = nvme_find_ns_head(ctrl->subsys, nsid);
...@@ -3514,32 +3517,29 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid, ...@@ -3514,32 +3517,29 @@ static int nvme_init_ns_head(struct nvme_ns *ns, unsigned nsid,
} }
head->shared = is_shared; head->shared = is_shared;
} else { } else {
ret = -EINVAL;
if (!is_shared || !head->shared) { if (!is_shared || !head->shared) {
dev_err(ctrl->device, dev_err(ctrl->device,
"Duplicate unshared namespace %d\n", "Duplicate unshared namespace %d\n", nsid);
nsid); goto out_put_ns_head;
ret = -EINVAL;
nvme_put_ns_head(head);
goto out_unlock;
} }
if (!nvme_ns_ids_equal(&head->ids, &ids)) { if (!nvme_ns_ids_equal(&head->ids, &ids)) {
dev_err(ctrl->device, dev_err(ctrl->device,
"IDs don't match for shared namespace %d\n", "IDs don't match for shared namespace %d\n",
nsid); nsid);
ret = -EINVAL; goto out_put_ns_head;
nvme_put_ns_head(head);
goto out_unlock;
} }
} }
list_add_tail(&ns->siblings, &head->list); list_add_tail(&ns->siblings, &head->list);
ns->head = head; ns->head = head;
mutex_unlock(&ctrl->subsys->lock);
return 0;
out_put_ns_head:
nvme_put_ns_head(head);
out_unlock: out_unlock:
mutex_unlock(&ctrl->subsys->lock); mutex_unlock(&ctrl->subsys->lock);
out:
if (ret > 0)
ret = blk_status_to_errno(nvme_error_status(ret));
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment