Re: [PATCH 33/76] uas: Pack iu struct definitions

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

 



Hi,

On 03/07/2014 04:41 PM, David Laight wrote:
> From: Of Sarah Sharp
>> From: Hans de Goede <hdegoede@xxxxxxxxxx>
>>
>> The iu struct definitions are usb packet definitions, so no alignment should
>> happen. Notice that assuming 32 bit alignment this does not make any
>> difference at all.
>>
>> Signed-off-by: Hans de Goede <hdegoede@xxxxxxxxxx>
>> Signed-off-by: Sarah Sharp <sarah.a.sharp@xxxxxxxxxxxxxxx>
>> ---
>>  include/linux/usb/uas.h | 10 +++++-----
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/include/linux/usb/uas.h b/include/linux/usb/uas.h
>> index 772b66bcdd7d..3fc8e8b9f043 100644
>> --- a/include/linux/usb/uas.h
>> +++ b/include/linux/usb/uas.h
>> @@ -9,7 +9,7 @@ struct iu {
>>  	__u8 iu_id;
>>  	__u8 rsvd1;
>>  	__be16 tag;
>> -};
>> +} __attribute__((__packed__));
> 
> I don't want to block these patches, but the above will make
> a difference.
> 
> On cpus that don't support misaligned memory transfers the
> compiler will have to generate code that does byte accesses
> and shifts in order to access 16 and 32 bit members of packed
> structures.
> 
> So you should really only mark structures as packed if they
> will occur on misaligned boundaries.

This is not about alignment, this is about holes in the
structure not being allowed, as it represents on the wire data
which has no holes in it.

Since we cannot know in advance what the alignment rules for
members inside structures on new archs will be, the only
way to ensure this is to pack the struct.

Note that *ALL* usb device drivers do the same.

Regards,

Hans
--
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