]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
nvme-pci: use struct_size for allocation struct nvme_dev
authorChristoph Hellwig <hch@lst.de>
Mon, 12 May 2025 15:20:44 +0000 (17:20 +0200)
committerChristoph Hellwig <hch@lst.de>
Tue, 20 May 2025 03:34:27 +0000 (05:34 +0200)
This avoids open coding the variable size array arithmetics.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>
Reviewed-by: Caleb Sander Mateos <csander@purestorage.com>
Reviewed-by: Leon Romanovsky <leon@kernel.org>
drivers/nvme/host/pci.c

index 2dbe6757e1a346e6335f9f17d339c87a94120ef9..1098eb17890b26e6c00f03ba86010afe5f08b6ca 100644 (file)
@@ -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);