From: Christoph Hellwig Date: Mon, 12 May 2025 15:20:44 +0000 (+0200) Subject: nvme-pci: use struct_size for allocation struct nvme_dev X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=de65e642644a20576af4e9d88fcbd911766c6b57;p=users%2Fjedix%2Flinux-maple.git nvme-pci: use struct_size for allocation struct nvme_dev This avoids open coding the variable size array arithmetics. Signed-off-by: Christoph Hellwig Reviewed-by: Keith Busch Reviewed-by: Kanchan Joshi Reviewed-by: Caleb Sander Mateos Reviewed-by: Leon Romanovsky --- diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 2dbe6757e1a3..1098eb17890b 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);