Re: [PATCH 31/68] uas: Pack iu struct definitions

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

 



Hi,

On 11/15/2013 04:29 PM, David Laight wrote:
From: Of Hans de Goede

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>
---
  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 772b66b..3fc8e8b 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__));

Won't this cause the compiler to generate multiple byte accesses
for the 'tag' field in systems that don't support misaligned
accesses.

The tag field is aligned to a multiple of its size, so that should not
happen, unless some system wants 32 bits alignment for 16 bit variables.

And on such a system we want the compiler to generate byte accesses,
to avoid throwing an unaligned memory access error.

We cannot allow the compiler to add padding to avoid such unaligned
accesses, since this struct is send as a blob over usb, and the sending
device will not insert any padding, iow this struct represent
data as it is on the wire, not how the data would (optimally) be represented
in host memory.

I'd have thought that 'packed' should only be specified on structures
that are likely to be misaligned in memory.

Without packed struct members will never be mis-aligned in memory as the
compiler will simply add padding. packed is used when the struct represent
data coming from an outside source, ie a file or a socket, or in this case
an usb data packet.

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