RE: MTD pointer alignment

Gavin Lambert
2006-12-04T21:18:06Z

Quoth David Woodhouse [dwmw2@infradead.org]:
> That's news to me. If we don't always align to sizeof(int)
> and have appropriate (i.e. three bytes) padding after the
> initial 'char' field, then surely the 'int' fields are
> sometimes going to be misaligned?
>
> What platform is this? Precisely how is it padded/aligned?

The int fields do get their natural alignment (ie. three bytes padding
after the initial char). But that initial char (and the structure as a
whole) is not necessarily aligned on a four-byte boundary.

This is on Coldfire, using m68k-elf-gcc 3.4.4.

Test case for making it go wrong was embedding it in a structure similar
to this:

struct some_device
{
u8 a_byte_field;
struct mtd_info mtd;
struct device dev;
};

The compiler inserted one single byte of padding between the byte field
and the MTD structure, making the structure aligned on a 2-byte
boundary, not a 4-byte one.

However I've now looked at the latest MTD sources (in 2.6.18) and it
looks like this issue may be moot, since file->private_data is now
pointing at some other structure rather than pointing directly at the
mtd_info. I didn't check where you're keeping your OTP mode info now,
but as long as you're not hijacking bits then it shouldn't be a problem
:)