[PATCH 7/7] nvme-pci: use struct_size for allocation struct nvme_dev

Caleb Sander Mateos csander at purestorage.com
Wed May 14 11:28:44 PDT 2025


On Tue, May 13, 2025 at 12:00 AM Christoph Hellwig <hch at lst.de> wrote:
>
> This avoid open coding the variable size array arithmetics.

typo:  "avoid" -> "avoids"?

>
> Signed-off-by: Christoph Hellwig <hch at lst.de>

Reviewed-by: Caleb Sander Mateos <csander at purestorage.com>

> ---
>  drivers/nvme/host/pci.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index 5396fe30eb94..0efbc9329291 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -3212,8 +3212,8 @@ static struct nvme_dev *nvme_pci_alloc_dev(struct pci_dev *pdev,
>         struct nvme_dev *dev;
>         int ret = -ENOMEM;
>
> -       dev = kzalloc_node(sizeof(*dev) + nr_node_ids *
> -                       sizeof(*dev->descriptor_pools), GFP_KERNEL, node);
> +       dev = kzalloc_node(struct_size(dev, descriptor_pools, nr_node_ids),
> +                       GFP_KERNEL, node);
>         if (!dev)
>                 return ERR_PTR(-ENOMEM);
>         INIT_WORK(&dev->ctrl.reset_work, nvme_reset_work);
> --
> 2.47.2
>



More information about the Linux-nvme mailing list