Skip to contentSkip to conversation

usb: Guarantee alignment of the string descriptor

PATCH New Andy Shevchenko 2 participants 2 messages Aug 29, 2019 – Aug 30, 2019 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: Guarantee alignment of the string descriptor

GCC 9.x starts complaining about potential misalignment of the pointer to the array (in this case alignment=2) in the packed (alignment=1) structures.

drivers/usb/gadget/composite.c:545:23: warning: taking address of packed member of ‘struct usb_string_descriptor’ may result in an unaligned pointer value [-Waddress-of-packed-member]
545 | collect_langs(sp, s->wData);

drivers/usb/gadget/composite.c:550:24: warning: taking address of packed member of ‘struct usb_string_descriptor’ may result in an unaligned pointer value [-Waddress-of-packed-member]
550 | collect_langs(sp, s->wData);

drivers/usb/gadget/composite.c:555:25: warning: taking address of packed member of ‘struct usb_string_descriptor’ may result in an unaligned pointer value [-Waddress-of-packed-member]
555 | collect_langs(sp, s->wData);

Define structure alignment to be 2 to guarantee alignment of its members.

---
 include/linux/usb/ch9.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/usb/ch9.h +1 -1
index 264c9712a3..a9b3c2709a 100644
@@ -336,7 +336,7 @@ struct usb_string_descriptor {
 	__u8  bDescriptorType;
 
 	__le16 wData[1];		/* UTF-16LE encoded */
-} __attribute__ ((packed));
+} __attribute__ ((packed, aligned(2)));
 
 /* note that "string" zero is special, it holds language codes that
  * the device supports, not Unicode characters.
Signature · 1 line
2.23.0.rc1
#1 lore raw

PATCH 1/1 usb: Guarantee alignment of the string descriptor

Quoted 13 lines · Andy Shevchenko

GCC 9.x starts complaining about potential misalignment of the pointer to the array (in this case alignment=2) in the packed (alignment=1) structures.

drivers/usb/gadget/composite.c:545:23: warning: taking address of packed member of ‘struct usb_string_descriptor’ may result in an unaligned pointer value [-Waddress-of-packed-member]
545 | collect_langs(sp, s->wData);

drivers/usb/gadget/composite.c:550:24: warning: taking address of packed member of ‘struct usb_string_descriptor’ may result in an unaligned pointer value [-Waddress-of-packed-member]
550 | collect_langs(sp, s->wData);

drivers/usb/gadget/composite.c:555:25: warning: taking address of packed member of ‘struct usb_string_descriptor’ may result in an unaligned pointer value [-Waddress-of-packed-member]
555 | collect_langs(sp, s->wData);

Quoted 7 lines

Define structure alignment to be 2 to guarantee alignment of its members.

---
 include/linux/usb/ch9.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)