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

Christoph Hellwig hch at lst.de
Tue Sep 29 14:29:03 EDT 2020


On Mon, Sep 28, 2020 at 02:27:37PM +0000, Damien Le Moal wrote:
> > 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.

I could.  This is a pretty common style in Linux code, though.

> > @@ -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.

Well, ensuring that nvme_identify_ns returns an error if NCAP is 0 is
all that this patch does in addition to removing the checks in the
callers.



More information about the Linux-nvme mailing list