[PATCH 10/13] nvme-pci: simplify nvme_dbbuf_dma_alloc

Sagi Grimberg sagi at grimberg.me
Sun Nov 13 22:28:59 PST 2022


> Move the OACS check and the error checking into nvme_dbbuf_dma_alloc so
> that an upcoming second caller doesn't have to duplicate this boilerplate
> code.
> 
> Signed-off-by: Christoph Hellwig <hch at lst.de>
> ---
>   drivers/nvme/host/pci.c | 32 ++++++++++++++++----------------
>   1 file changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index c2e3a87237da8..4da339690ec67 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -239,10 +239,13 @@ static inline unsigned int nvme_dbbuf_size(struct nvme_dev *dev)
>   	return dev->nr_allocated_queues * 8 * dev->db_stride;
>   }
>   
> -static int nvme_dbbuf_dma_alloc(struct nvme_dev *dev)
> +static void nvme_dbbuf_dma_alloc(struct nvme_dev *dev)
>   {
>   	unsigned int mem_size = nvme_dbbuf_size(dev);
>   
> +	if (!(dev->ctrl.oacs & NVME_CTRL_OACS_DBBUF_SUPP))
> +		return;
> +

I usually dislike functions that may or may not operate based on
caps check inside them. Even if there are more than one call-site.
But that is a personal taste.

Reviewed-by: Sagi Grimberg <sagi at grimberg.me>



More information about the Linux-nvme mailing list