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

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

 



On Mon, Jun 20, 2011 at 03:14:26PM -0400, Nicolas Pitre wrote:
> If you need that structure to be packed then so be it and nothing else 
> can be done about it.
> 
> However if you have:
> 
> struct foo {
> 	u32 c;
> 	u64 d;
> 	u32 e;
> };
> 
> 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().

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;
};

?

The last gotcha here is struct size.

struct bar {
	u8 a;
	u8 b;
};

May be 2 on some Linux supporting architectures, or may be larger due to
tail padding.  Eg, ARM OABI will add two bytes of tail padding to this.

If we assume that 'struct foo' will be laid out as we desire (iow, no
additional padding with naturally aligned elements) then the only
remaining issue is sizeof(struct), and that's a whole different ballgame.
That shouldn't be solved by packed.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux