Re: [PATCH v2 1/2] PCI: Add new method for registering PCI hosts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [ARM Kernel]     [Linux ARM]     [Linux ARM MSM]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux