[PATCH 07/20] nvme: lift the check for an unallocated namespace into nvme_identify_ns

Damien Le Moal Damien.LeMoal at wdc.com
Mon Sep 28 10:27:37 EDT 2020


On 2020/09/28 21:35, Christoph Hellwig wrote:
> Move the check from the two callers into the common helper.
> 
> Signed-off-by: Christoph Hellwig <hch at lst.de>
> ---
>  drivers/nvme/host/core.c | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index fede487f6e043f..7b1423c7e7fc58 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -1381,9 +1381,16 @@ static int nvme_identify_ns(struct nvme_ctrl *ctrl,
>  	error = nvme_submit_sync_cmd(ctrl->admin_q, &c, *id, sizeof(**id));
>  	if (error) {
>  		dev_warn(ctrl->device, "Identify namespace failed (%d)\n", error);
> -		kfree(*id);
> +		goto out_free_id;
>  	}
>  
> +	error = -ENODEV;

You could move this inside the if.

> +	if ((*id)->ncap == 0) /* namespace not allocated or attached */
> +		goto out_free_id;
> +	return 0;
> +
> +out_free_id:
> +	kfree(*id);
>  	return error;
>  }
>  
> @@ -2169,11 +2176,6 @@ static int nvme_validate_ns(struct nvme_ns *ns)
>  	if (ret)
>  		goto out;
>  
> -	if (id->ncap == 0) {
> -		ret = -ENODEV;
> -		goto free_id;
> -	}
> -
>  	ret = nvme_report_ns_ids(ctrl, ns->head->ns_id, id, &ids);
>  	if (ret)
>  		goto free_id;
> @@ -3913,9 +3915,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
>  	if (ret)
>  		goto out_free_queue;
>  
> -	if (id->ncap == 0)	/* no namespace (legacy quirk) */
> -		goto out_free_id;

There is a call to nvme_identify_ns() above this, and I guess it is OK to assume
that that function will never return success if the ns cap is 0, right ?
If so, then this change looks OK.

> -
>  	ret = nvme_init_ns_head(ns, nsid, id);
>  	if (ret)
>  		goto out_free_id;
> 
-- 
Damien Le Moal
Western Digital Research



More information about the Linux-nvme mailing list