[BUG] common/usb.c: taking address of packed member of ‘struct usb_device_descriptor’ may result in an unaligned pointer value

Heinrich Schuchardt xypron.glpk at gmx.de
Mon Dec 16 10:44:13 CET 2019


Hello Marek,

with powerpc64-linux-gnu-gcc, version 9.2.1, big endian I see the errors
below.

struct usb_device_descriptor is naturally packed. Why do we need the
packed attribute in include/linux/usb/ch9.h?

If it is needed, we should replace le16_to_cpus() by an alignment
friendly implementation in common/usb.c, e.g. using u8* pointers.

   CC      common/usb.o
In file included from ./arch/powerpc/include/asm/byteorder.h:82,
                  from ./arch/powerpc/include/asm/bitops.h:8,
                  from include/linux/bitops.h:136,
                  from include/common.h:26,
                  from common/usb.c:28:
common/usb.c: In function ‘usb_select_config’:
common/usb.c:1081:15: error: taking address of packed member of ‘struct
usb_device_descriptor’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
  1081 |  le16_to_cpus(&dev->descriptor.bcdUSB);
include/linux/byteorder/big_endian.h:98:38: note: in definition of macro
‘__le16_to_cpus’
    98 | #define __le16_to_cpus(x) __swab16s((x))
       |                                      ^
common/usb.c:1081:2: note: in expansion of macro ‘le16_to_cpus’
  1081 |  le16_to_cpus(&dev->descriptor.bcdUSB);
       |  ^~~~~~~~~~~~
common/usb.c:1082:15: error: taking address of packed member of ‘struct
usb_device_descriptor’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
  1082 |  le16_to_cpus(&dev->descriptor.idVendor);
include/linux/byteorder/big_endian.h:98:38: note: in definition of macro
‘__le16_to_cpus’
    98 | #define __le16_to_cpus(x) __swab16s((x))
       |                                      ^
common/usb.c:1082:2: note: in expansion of macro ‘le16_to_cpus’
  1082 |  le16_to_cpus(&dev->descriptor.idVendor);
       |  ^~~~~~~~~~~~
common/usb.c:1083:15: error: taking address of packed member of ‘struct
usb_device_descriptor’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
  1083 |  le16_to_cpus(&dev->descriptor.idProduct);
include/linux/byteorder/big_endian.h:98:38: note: in definition of macro
‘__le16_to_cpus’
    98 | #define __le16_to_cpus(x) __swab16s((x))
       |                                      ^
common/usb.c:1083:2: note: in expansion of macro ‘le16_to_cpus’
  1083 |  le16_to_cpus(&dev->descriptor.idProduct);
       |  ^~~~~~~~~~~~
common/usb.c:1084:15: error: taking address of packed member of ‘struct
usb_device_descriptor’ may result in an unaligned pointer value
[-Werror=address-of-packed-member]
  1084 |  le16_to_cpus(&dev->descriptor.bcdDevice);
include/linux/byteorder/big_endian.h:98:38: note: in definition of macro
‘__le16_to_cpus’
    98 | #define __le16_to_cpus(x) __swab16s((x))
       |                                      ^
common/usb.c:1084:2: note: in expansion of macro ‘le16_to_cpus’
  1084 |  le16_to_cpus(&dev->descriptor.bcdDevice);
       |  ^~~~~~~~~~~~

Best regards

Heinrich


More information about the U-Boot mailing list