[PATCH 09/13] nvme: factor out a nvme_tryget_ns_head helper
Kanchan Joshi
joshiiitr at gmail.com
Fri Apr 9 10:18:20 BST 2021
On Thu, Apr 8, 2021 at 5:50 PM Christoph Hellwig <hch at lst.de> wrote:
>
> Add a helper to avoid opencoding ns_head->ref manipulations.
>
> Signed-off-by: Christoph Hellwig <hch at lst.de>
> ---
> drivers/nvme/host/core.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 98d87bff4ca37f..9637f2e5e9232c 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -549,6 +549,11 @@ static void nvme_free_ns_head(struct kref *ref)
> kfree(head);
> }
>
> +static bool nvme_tryget_ns_head(struct nvme_ns_head *head)
> +{
> + return kref_get_unless_zero(&head->ref);
> +}
> +
> static void nvme_put_ns_head(struct nvme_ns_head *head)
> {
> kref_put(&head->ref, nvme_free_ns_head);
> @@ -1975,9 +1980,7 @@ static const struct block_device_operations nvme_bdev_ops = {
> #ifdef CONFIG_NVME_MULTIPATH
> static int nvme_ns_head_open(struct block_device *bdev, fmode_t mode)
> {
> - struct nvme_ns_head *head = bdev->bd_disk->private_data;
> -
> - if (!kref_get_unless_zero(&head->ref))
> + if (!nvme_tryget_ns_head(bdev->bd_disk->private_data))
> return -ENXIO;
> return 0;
> }
This new helper needs to be added inside nvme_find_ns_head() as well?
Reviewed-by: Kanchan Joshi <joshi.k at samsung.com>
--
Kanchan
More information about the Linux-nvme
mailing list