[U-Boot] [PATCH] imx: ventana: Avoid undefined behaviour

Tim Harvey tharvey at gateworks.com
Fri Aug 22 20:55:20 CEST 2014


On Fri, Aug 22, 2014 at 12:46 AM, Thierry Reding
<thierry.reding at gmail.com> wrote:
> From: Thierry Reding <treding at nvidia.com>
>
> The leds array within struct ventana has space for 3 elements, but the
> setup_board_gpio() function tries to set up 4 GPIOs for LEDs. Recent
> versions of GCC complain about that:
>
>         board/gateworks/gw_ventana/gw_ventana.c: In function 'setup_board_gpio':
>         board/gateworks/gw_ventana/gw_ventana.c:987:27: warning: iteration 3u invokes undefined behavior [-Waggressive-loop-optimizations]
>            if (gpio_cfg[board].leds[i])
>                                    ^
>         board/gateworks/gw_ventana/gw_ventana.c:986:2: note: containing loop
>           for (i = 0; i < 4; i++) {
>           ^
>
> Fix this by making the upper bound of the loop match the array size.
>
> Signed-off-by: Thierry Reding <treding at nvidia.com>
> ---
>  board/gateworks/gw_ventana/gw_ventana.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/board/gateworks/gw_ventana/gw_ventana.c b/board/gateworks/gw_ventana/gw_ventana.c
> index 9d2651f0cbf1..01212367c396 100644
> --- a/board/gateworks/gw_ventana/gw_ventana.c
> +++ b/board/gateworks/gw_ventana/gw_ventana.c
> @@ -983,7 +983,7 @@ static void setup_board_gpio(int board)
>         gpio_direction_output(gpio_cfg[board].pcie_rst, 0);
>
>         /* turn off (active-high) user LED's */
> -       for (i = 0; i < 4; i++) {
> +       for (i = 0; i < ARRAY_SIZE(gpio_cfg[board].leds); i++) {
>                 if (gpio_cfg[board].leds[i])
>                         gpio_direction_output(gpio_cfg[board].leds[i], 1);
>         }
> --
> 2.0.4
>

Thanks for catching and fixing this Thierry!

Acked-by: Tim Harvey <tharvey at gateworks.com>

Tim


More information about the U-Boot mailing list