PCI: hv: Use struct_size() helper
authorGustavo A. R. Silva <gustavoars@kernel.org>
Mon, 25 May 2020 16:43:19 +0000 (11:43 -0500)
committerLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Thu, 28 May 2020 14:37:43 +0000 (15:37 +0100)
commitd0684fd0bd79395e074dd668feee5d53b134b1a3
treeb3d4cb8b5de9f5acb9764b74ad4466a24f9dff1d
parentc81992e7f4aa19a055dbff5bd6c6d5ff9408f2fb
PCI: hv: Use struct_size() helper

One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array. For example:

struct hv_dr_state {
...
        struct hv_pcidev_description func[];
};

struct pci_bus_relations {
...
        struct pci_function_description func[];
} __packed;

Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes.

So, replace the following forms:

offsetof(struct hv_dr_state, func) +
(sizeof(struct hv_pcidev_description) *
(relations->device_count))

offsetof(struct pci_bus_relations, func) +
(sizeof(struct pci_function_description) *
(bus_rel->device_count))

with:

struct_size(dr, func, relations->device_count)

and

struct_size(bus_rel, func, bus_rel->device_count)

respectively.

Link: https://lore.kernel.org/r/20200525164319.GA13596@embeddedor
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reviewed-by: Wei Liu <wei.liu@kernel.org>
drivers/pci/controller/pci-hyperv.c