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

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