Skip to contentSkip to conversation

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

BUG Heinrich Schuchardt 2 participants 2 messages Dec 16, 2019

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 1 line · Heinrich Schuchardt

Hello Marek,

Hi,

Quoted 2 lines

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

Are you building this with some additional extra flags ?

Quoted 2 lines

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

Did you check git log ? Maybe there is some hint.

[...]