Re: [PATCH] USB: ehci: use packed, aligned(4) instead of removing the packed attribute

From: Arnd Bergmann
Date: Mon Jun 20 2011 - 16:15:34 EST


On Monday 20 June 2011 21:32:13 Russell King - ARM Linux wrote:
> > Here the d member is not naturally aligned. On most architectures,
> > including ARM with the ABI currently in use, the compiler would insert a
> > 32-bit padding between c and d.
>
> And if 'struct foo' represents a structure in device memory, the end
> result is highly unpredicable whether or not you have padding or
> accessors to load 'd' there. So, you would not have such a structure
> describing a data structure in memory returned by ioremap().

Right.

> Now, the real question is: is there any architecture which is (or may
> be) supported by the Linux kernel which would add padding to:
>
> struct foo {
> u8 a;
> u8 b;
> u16 c;
> u32 d;
> u64 e;
> };

This is the other issue, which we were facing in the scsi drivers.
If an architecture requires padding because some members require
larger than natural alignment here, the 'packed' should be applied
to that member, in order to change the alignment of that member.

Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/