public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] imx: ventana: Avoid undefined behaviour
@ 2014-08-22  7:46 Thierry Reding
  2014-08-22 18:55 ` Tim Harvey
  2014-09-09 14:27 ` Stefano Babic
  0 siblings, 2 replies; 3+ messages in thread
From: Thierry Reding @ 2014-08-22  7:46 UTC (permalink / raw)
  To: u-boot

From: Thierry Reding <treding@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@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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH] imx: ventana: Avoid undefined behaviour
  2014-08-22  7:46 [U-Boot] [PATCH] imx: ventana: Avoid undefined behaviour Thierry Reding
@ 2014-08-22 18:55 ` Tim Harvey
  2014-09-09 14:27 ` Stefano Babic
  1 sibling, 0 replies; 3+ messages in thread
From: Tim Harvey @ 2014-08-22 18:55 UTC (permalink / raw)
  To: u-boot

On Fri, Aug 22, 2014 at 12:46 AM, Thierry Reding
<thierry.reding@gmail.com> wrote:
> From: Thierry Reding <treding@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@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@gateworks.com>

Tim

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH] imx: ventana: Avoid undefined behaviour
  2014-08-22  7:46 [U-Boot] [PATCH] imx: ventana: Avoid undefined behaviour Thierry Reding
  2014-08-22 18:55 ` Tim Harvey
@ 2014-09-09 14:27 ` Stefano Babic
  1 sibling, 0 replies; 3+ messages in thread
From: Stefano Babic @ 2014-09-09 14:27 UTC (permalink / raw)
  To: u-boot

On 22/08/2014 09:46, Thierry Reding wrote:
> From: Thierry Reding <treding@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@nvidia.com>
> ---

Applied to u-boot-imx, thanks !

Best regards,
Stefano Babic



-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-09-09 14:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-22  7:46 [U-Boot] [PATCH] imx: ventana: Avoid undefined behaviour Thierry Reding
2014-08-22 18:55 ` Tim Harvey
2014-09-09 14:27 ` Stefano Babic

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox