From: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>
To: Liviu Dudau <liviu.dudau-5wv7dgnIgG8@public.gmane.org>
Cc: Thierry Reding
<thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Bjorn Helgaas <bhelgaas-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
Tomasz Nowicki <tn-nYOzD4b6Jr9Wk0Htik3J/w@public.gmane.org>,
linux-pci-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v2 1/2] PCI: Add new method for registering PCI hosts
Date: Fri, 01 Jul 2016 17:58:50 +0200 [thread overview]
Message-ID: <5683703.E1NK8ak7mr@wuerfel> (raw)
In-Reply-To: <20160701154046.GE8609-2JSQmVVBSi7ZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
On Friday, July 1, 2016 4:40:46 PM CEST Liviu Dudau wrote:
> On Fri, Jul 01, 2016 at 05:17:11PM +0200, Arnd Bergmann wrote:
> > On Friday, July 1, 2016 3:52:44 PM CEST Liviu Dudau wrote:
> > >
> > > >
> > > > or do you mean we should have extra alignment in there so the
> > > > private pointer has a minimum alignment higher than the
> > > > alignment of struct pci_host_bridge?
> > >
> > > but this ^. bridge pointer arithmetic means +1 is not necessarily +sizeof(struct pci_host_bridge)
> > > bytes. AFAIK that can be rounded to the nearest natural alignment for pointers on that
> > > architecture.
> >
> > No, that's not how it works.
>
> Really? If struct foo takes 31 bytes, and struct foo *p = (struct foo*)64, what's p's
> value after p++ ? 95? I thought the compiler is allowed to consider the structure padded so that
> p++ is 96.
In that example, sizeof(struct foo) is 32, so we get to the right result,
for any type, this is true:
(char *)((struct foo *)p + 1) == (char *)p + sizeof(struct foo);
However, there is indeed a problem in the case that the private structure
requires a larger alignment than struct pci_host_bridge, so adding some
bytes for alignment the way that alloc_etherdev() does is probably
a good idea to be on the safe side, so we could do
bridge = kzalloc(ALIGN(sizeof(struct pci_host_bridge), ARCH_KMALLOC_MINALIGN) +
sizeof_priv, GFP_KERNEL);
priv = PTR_ALIGN(bridge + 1, ARCH_KMALLOC_MINALIGN);
which will guarantee that both bridge and priv are aligned to
ARCH_KMALLOC_MINALIGN and the allocation is large enough to hold
both.
Arnd
next prev parent reply other threads:[~2016-07-01 15:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-30 15:19 [PATCH v2 1/2] PCI: Add new method for registering PCI hosts Thierry Reding
2016-06-30 15:19 ` [PATCH v2 2/2] PCI: tegra: Use new pci_register_host() interface Thierry Reding
[not found] ` <20160630151931.29216-1-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-06-30 15:37 ` [PATCH v2 1/2] PCI: Add new method for registering PCI hosts Arnd Bergmann
2016-07-01 14:14 ` Liviu Dudau
[not found] ` <20160701141447.GB8609-2JSQmVVBSi7ZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2016-07-01 14:24 ` Arnd Bergmann
2016-07-01 14:52 ` Liviu Dudau
[not found] ` <20160701145244.GD8609-2JSQmVVBSi7ZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2016-07-01 15:17 ` Arnd Bergmann
2016-07-01 15:40 ` Liviu Dudau
[not found] ` <20160701154046.GE8609-2JSQmVVBSi7ZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2016-07-01 15:58 ` Arnd Bergmann [this message]
2016-07-01 14:46 ` Liviu Dudau
[not found] ` <20160701144648.GC8609-2JSQmVVBSi7ZROr8t4l/smS4ubULX0JqMm0uRHvK7Nw@public.gmane.org>
2016-07-01 15:44 ` Arnd Bergmann
2016-07-01 16:09 ` Liviu Dudau
2016-07-01 16:30 ` Arnd Bergmann
2016-07-04 9:56 ` Liviu Dudau
2016-07-04 13:46 ` Arnd Bergmann
2016-07-28 20:43 ` Bjorn Helgaas
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=5683703.E1NK8ak7mr@wuerfel \
--to=arnd-r2ngtmty4d4@public.gmane.org \
--cc=bhelgaas-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=linux-pci-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=liviu.dudau-5wv7dgnIgG8@public.gmane.org \
--cc=thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=tn-nYOzD4b6Jr9Wk0Htik3J/w@public.gmane.org \
/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