Commit 4c74d1f8 authored by Kanchan Joshi's avatar Kanchan Joshi Committed by Christoph Hellwig

nvme: add nvme_get_ns helper

Add a helper to avoid opencoding ns->kref increment.
Decrement is already done via nvme_put_ns helper.
Signed-off-by: default avatarKanchan Joshi <joshi.k@samsung.com>
Reviewed-by: default avatarChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent 48145b62
...@@ -576,6 +576,11 @@ static void nvme_free_ns(struct kref *kref) ...@@ -576,6 +576,11 @@ static void nvme_free_ns(struct kref *kref)
kfree(ns); kfree(ns);
} }
static inline bool nvme_get_ns(struct nvme_ns *ns)
{
return kref_get_unless_zero(&ns->kref);
}
void nvme_put_ns(struct nvme_ns *ns) void nvme_put_ns(struct nvme_ns *ns)
{ {
kref_put(&ns->kref, nvme_free_ns); kref_put(&ns->kref, nvme_free_ns);
...@@ -1494,7 +1499,7 @@ static int nvme_ns_open(struct nvme_ns *ns) ...@@ -1494,7 +1499,7 @@ static int nvme_ns_open(struct nvme_ns *ns)
/* should never be called due to GENHD_FL_HIDDEN */ /* should never be called due to GENHD_FL_HIDDEN */
if (WARN_ON_ONCE(nvme_ns_head_multipath(ns->head))) if (WARN_ON_ONCE(nvme_ns_head_multipath(ns->head)))
goto fail; goto fail;
if (!kref_get_unless_zero(&ns->kref)) if (!nvme_get_ns(ns))
goto fail; goto fail;
if (!try_module_get(ns->ctrl->ops->module)) if (!try_module_get(ns->ctrl->ops->module))
goto fail_put_ns; goto fail_put_ns;
...@@ -3582,7 +3587,7 @@ struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid) ...@@ -3582,7 +3587,7 @@ struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid)
down_read(&ctrl->namespaces_rwsem); down_read(&ctrl->namespaces_rwsem);
list_for_each_entry(ns, &ctrl->namespaces, list) { list_for_each_entry(ns, &ctrl->namespaces, list) {
if (ns->head->ns_id == nsid) { if (ns->head->ns_id == nsid) {
if (!kref_get_unless_zero(&ns->kref)) if (!nvme_get_ns(ns))
continue; continue;
ret = ns; ret = ns;
break; break;
......
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