Skip to content
Snippets Groups Projects
Commit dc73cbe7 authored by Thierry Reding's avatar Thierry Reding Committed by Stefano Babic
Browse files

imx: ventana: Avoid undefined behaviour


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: default avatarThierry Reding <treding@nvidia.com>
Acked-by: default avatarTim Harvey <tharvey@gateworks.com>
parent 021e79c8
No related branches found
No related tags found
No related merge requests found
...@@ -1061,7 +1061,7 @@ static void setup_board_gpio(int board) ...@@ -1061,7 +1061,7 @@ static void setup_board_gpio(int board)
#endif #endif
/* turn off (active-high) user LED's */ /* 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]) if (gpio_cfg[board].leds[i])
gpio_direction_output(gpio_cfg[board].leds[i], 1); gpio_direction_output(gpio_cfg[board].leds[i], 1);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment