usb: composite: fix unalinged address about packed structure 91/220391/1
authorJaehoon Chung <jh80.chung@samsung.com>
Wed, 18 Dec 2019 03:27:58 +0000 (12:27 +0900)
committerJaehoon Chung <jh80.chung@samsung.com>
Wed, 18 Dec 2019 03:45:29 +0000 (12:45 +0900)
Since upgrading to gcc9, warnings are issued:
"taking address of packed member of ‘...’ may result in an unaligned
pointer value"

This patch is refered to below commit
- commit 616ebd8b9cb "usb: composite: fix possible alignment issues"

Change-Id: Idceb5b56f7daf1481de528f95a1a2f1f9b57c0dd
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
drivers/usb/gadget/composite.c

index d7b4f50..36caf5c 100644 (file)
@@ -52,6 +52,8 @@ extern void udelay(unsigned long usec);
 /* big enough to hold our biggest descriptor */
 #define USB_BUFSIZ     512
 
+typedef struct { __le16 val;} __attribute__((aligned(16))) __le16_packed;
+
 static struct usb_composite_driver *composite;
 
 /* Some systems will need runtime overrides for the  product identifers
@@ -641,20 +643,21 @@ done:
  * the host side.
  */
 
-static void collect_langs(struct usb_gadget_strings **sp, __le16 *buf)
+static void collect_langs(struct usb_gadget_strings **sp, void *buf)
 {
        const struct usb_gadget_strings *s;
        u16                             language;
-       __le16                          *tmp;
+       __le16_packed                   *tmp;
+       __le16_packed                   *end = (buf + 252);
 
        while (*sp) {
                s = *sp;
                language = cpu_to_le16(s->language);
-               for (tmp = buf; *tmp && tmp < &buf[126]; tmp++) {
-                       if (*tmp == language)
+               for (tmp = buf; tmp->val && tmp < end; tmp++) {
+                       if (tmp->val == language)
                                goto repeat;
                }
-               *tmp++ = language;
+               tmp->val = language;
 repeat:
                sp++;
        }