linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu@kernel.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: "K. Y. Srinivasan" <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	Stephen Hemminger <sthemmin@microsoft.com>,
	Wei Liu <wei.liu@kernel.org>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Rob Herring <robh@kernel.org>,
	Bjorn Helgaas <bhelgaas@google.com>,
	linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavo@embeddedor.com>,
	Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH] PCI: hv: Use struct_size() helper
Date: Tue, 26 May 2020 10:38:49 +0100	[thread overview]
Message-ID: <20200526093849.keva4hp775m4dzuo@debian> (raw)
In-Reply-To: <20200525164319.GA13596@embeddedor>

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@kernel.org>

Reviewed-by: Wei Liu <wei.liu@kernel.org>

FAOD I expect this patch to go through pci tree.

  reply	other threads:[~2020-05-26  9:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-25 16:43 [PATCH] PCI: hv: Use struct_size() helper Gustavo A. R. Silva
2020-05-26  9:38 ` Wei Liu [this message]
2020-05-28 14:41 ` Lorenzo Pieralisi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200526093849.keva4hp775m4dzuo@debian \
    --to=wei.liu@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=gustavo@embeddedor.com \
    --cc=gustavoars@kernel.org \
    --cc=haiyangz@microsoft.com \
    --cc=keescook@chromium.org \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=robh@kernel.org \
    --cc=sthemmin@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).