usb: Guarantee alignment of the string descriptor 71/227171/2 accepted/tizen/unified/20200311.130826 submit/tizen/20200310.094626
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 29 Aug 2019 14:46:07 +0000 (17:46 +0300)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Tue, 10 Mar 2020 06:39:55 +0000 (15:39 +0900)
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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
[sw0312.kim: apply from list https://patchwork.ozlabs.org/patch/1155376/, to remove gcc9 warning]
Suggested-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Id5b0f65266f452458623c49c46dee002c462a3b2

include/linux/usb/ch9.h

index d9822aa..f9d9dbb 100644 (file)
@@ -290,7 +290,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.