linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: ep93xx: fix incorrect array element size check
@ 2018-09-06 11:58 Colin King
  2018-09-06 12:44 ` Linus Walleij
  0 siblings, 1 reply; 7+ messages in thread
From: Colin King @ 2018-09-06 11:58 UTC (permalink / raw)
  To: Linus Walleij, linux-gpio; +Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently the while loop checks for the end of the array using
the size of egp->gc rather that the number of elements in the array,
so fix this. Also, perform the array size check first as stylistically
it is always good to bounds check on an array first before referencing
the array (in this case, we're just computing the address of an
element in an array so this is a moot point).

Fixes: fd935fc421e7 ("gpio: ep93xx: Do not pingpong irq numbers")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/gpio/gpio-ep93xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-ep93xx.c b/drivers/gpio/gpio-ep93xx.c
index 68a416fc3141..dd22ea19c3ed 100644
--- a/drivers/gpio/gpio-ep93xx.c
+++ b/drivers/gpio/gpio-ep93xx.c
@@ -76,7 +76,7 @@ static int ep93xx_gpio_port(struct gpio_chip *gc)
 	struct ep93xx_gpio *epg = gpiochip_get_data(gc);
 	int port = 0;
 
-	while (gc != &epg->gc[port] && port < sizeof(epg->gc))
+	while (port < ARRAY_SIZE(epg->gc) && gc != &epg->gc[port])
 		port++;
 
 	/* This should not happen but is there as a last safeguard */
-- 
2.17.1


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

end of thread, other threads:[~2018-09-06 15:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-06 11:58 [PATCH] gpio: ep93xx: fix incorrect array element size check Colin King
2018-09-06 12:44 ` Linus Walleij
2018-09-06 13:33   ` [PATCH] gpio: ep93xx: fix test for end of loop Dan Carpenter
2018-09-06 13:50     ` Colin Ian King
2018-09-06 14:48       ` Dan Carpenter
2018-09-06 15:18         ` Colin Ian King
2018-09-06 14:31     ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).