[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200526093849.keva4hp775m4dzuo@debian>
Date: Tue, 26 May 2020 10:38:49 +0100
From: Wei Liu <wei.liu@...nel.org>
To: "Gustavo A. R. Silva" <gustavoars@...nel.org>
Cc: "K. Y. Srinivasan" <kys@...rosoft.com>,
Haiyang Zhang <haiyangz@...rosoft.com>,
Stephen Hemminger <sthemmin@...rosoft.com>,
Wei Liu <wei.liu@...nel.org>,
Lorenzo Pieralisi <lorenzo.pieralisi@....com>,
Rob Herring <robh@...nel.org>,
Bjorn Helgaas <bhelgaas@...gle.com>,
linux-hyperv@...r.kernel.org, linux-pci@...r.kernel.org,
linux-kernel@...r.kernel.org,
"Gustavo A. R. Silva" <gustavo@...eddedor.com>,
Kees Cook <keescook@...omium.org>
Subject: Re: [PATCH] PCI: hv: Use struct_size() helper
On Mon, May 25, 2020 at 11:43:19AM -0500, Gustavo A. R. Silva wrote:
> 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.
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@...nel.org>
Reviewed-by: Wei Liu <wei.liu@...nel.org>
FAOD I expect this patch to go through pci tree.
Powered by blists - more mailing lists