usb: renesas_usbhs: tidyup original usbhsx_for_each_xxx macro
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Fri, 12 Jul 2013 05:32:31 +0000 (22:32 -0700)
committerFelipe Balbi <balbi@ti.com>
Mon, 29 Jul 2013 10:58:12 +0000 (13:58 +0300)
Current usbhsx_for_each_xxx macro will read out-of-array's
memory after last loop operation.
It was not good C language operation, and the binary which was
compiled by (at least) gcc 4.8.1 is broken
This patch tidyup these issues

Reported-by: Yusuke Goda <yusuke.goda.sx@renesas.com>
Reviewed-by: Takashi Yoshii <takashi.yoshii.zj@renesas.com>
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/renesas_usbhs/mod_gadget.c
drivers/usb/renesas_usbhs/mod_host.c
drivers/usb/renesas_usbhs/pipe.h

index 805940c..3385aeb 100644 (file)
@@ -77,9 +77,9 @@ struct usbhsg_recip_handle {
                struct usbhsg_gpriv, mod)
 
 #define __usbhsg_for_each_uep(start, pos, g, i)        \
-       for (i = start, pos = (g)->uep + i;     \
-            i < (g)->uep_size;                 \
-            i++, pos = (g)->uep + i)
+       for ((i) = start;                                       \
+            ((i) < (g)->uep_size) && ((pos) = (g)->uep + (i)); \
+            (i)++)
 
 #define usbhsg_for_each_uep(pos, gpriv, i)     \
        __usbhsg_for_each_uep(1, pos, gpriv, i)
index b868154..e40f565 100644 (file)
@@ -111,9 +111,9 @@ static const char usbhsh_hcd_name[] = "renesas_usbhs host";
        container_of(usbhs_mod_get(priv, USBHS_HOST), struct usbhsh_hpriv, mod)
 
 #define __usbhsh_for_each_udev(start, pos, h, i)       \
-       for (i = start, pos = (h)->udev + i;            \
-            i < USBHSH_DEVICE_MAX;                     \
-            i++, pos = (h)->udev + i)
+       for ((i) = start;                                               \
+            ((i) < USBHSH_DEVICE_MAX) && ((pos) = (h)->udev + (i));    \
+            (i)++)
 
 #define usbhsh_for_each_udev(pos, hpriv, i)    \
        __usbhsh_for_each_udev(1, pos, hpriv, i)
index b476fde..3e53498 100644 (file)
@@ -54,9 +54,9 @@ struct usbhs_pipe_info {
  * pipe list
  */
 #define __usbhs_for_each_pipe(start, pos, info, i)     \
-       for (i = start, pos = (info)->pipe + i;         \
-            i < (info)->size;                          \
-            i++, pos = (info)->pipe + i)
+       for ((i) = start;                                               \
+            ((i) < (info)->size) && ((pos) = (info)->pipe + (i));      \
+            (i)++)
 
 #define usbhs_for_each_pipe(pos, priv, i)                      \
        __usbhs_for_each_pipe(1, pos, &((priv)->pipe_info), i)