Skip to content

Commit 4c74d1f

Browse files
Kanchan JoshiChristoph Hellwig
authored andcommitted
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: Kanchan Joshi <joshi.k@samsung.com> Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 48145b6 commit 4c74d1f

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

drivers/nvme/host/core.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,11 @@ static void nvme_free_ns(struct kref *kref)
576576
kfree(ns);
577577
}
578578

579+
static inline bool nvme_get_ns(struct nvme_ns *ns)
580+
{
581+
return kref_get_unless_zero(&ns->kref);
582+
}
583+
579584
void nvme_put_ns(struct nvme_ns *ns)
580585
{
581586
kref_put(&ns->kref, nvme_free_ns);
@@ -1494,7 +1499,7 @@ static int nvme_ns_open(struct nvme_ns *ns)
14941499
/* should never be called due to GENHD_FL_HIDDEN */
14951500
if (WARN_ON_ONCE(nvme_ns_head_multipath(ns->head)))
14961501
goto fail;
1497-
if (!kref_get_unless_zero(&ns->kref))
1502+
if (!nvme_get_ns(ns))
14981503
goto fail;
14991504
if (!try_module_get(ns->ctrl->ops->module))
15001505
goto fail_put_ns;
@@ -3582,7 +3587,7 @@ struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid)
35823587
down_read(&ctrl->namespaces_rwsem);
35833588
list_for_each_entry(ns, &ctrl->namespaces, list) {
35843589
if (ns->head->ns_id == nsid) {
3585-
if (!kref_get_unless_zero(&ns->kref))
3590+
if (!nvme_get_ns(ns))
35863591
continue;
35873592
ret = ns;
35883593
break;

0 commit comments

Comments
 (0)