From: Colin King <colin.king@canonical.com> To: Linus Walleij <linus.walleij@linaro.org>, linux-gpio@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] gpio: ep93xx: fix incorrect array element size check Date: Thu, 6 Sep 2018 12:58:30 +0100 [thread overview] Message-ID: <20180906115830.19386-1-colin.king@canonical.com> (raw) 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
WARNING: multiple messages have this Message-ID (diff)
From: Colin King <colin.king@canonical.com> To: Linus Walleij <linus.walleij@linaro.org>, linux-gpio@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] gpio: ep93xx: fix incorrect array element size check Date: Thu, 06 Sep 2018 11:58:30 +0000 [thread overview] Message-ID: <20180906115830.19386-1-colin.king@canonical.com> (raw) 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
next reply other threads:[~2018-09-06 11:58 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-09-06 11:58 Colin King [this message] 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 12:44 ` Linus Walleij 2018-09-06 13:33 ` [PATCH] gpio: ep93xx: fix test for end of loop Dan Carpenter 2018-09-06 13:33 ` Dan Carpenter 2018-09-06 13:50 ` Colin Ian King 2018-09-06 13:50 ` Colin Ian King 2018-09-06 14:48 ` Dan Carpenter 2018-09-06 14:48 ` Dan Carpenter 2018-09-06 15:18 ` Colin Ian King 2018-09-06 15:18 ` Colin Ian King 2018-09-06 14:31 ` Linus Walleij 2018-09-06 14:31 ` Linus Walleij
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180906115830.19386-1-colin.king@canonical.com \ --to=colin.king@canonical.com \ --cc=kernel-janitors@vger.kernel.org \ --cc=linus.walleij@linaro.org \ --cc=linux-gpio@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.