* [PATCH] gpio: nomadik: remove BUG_ON() in nmk_gpio_populate_chip()
@ 2024-03-11 11:00 Dan Carpenter
2024-03-12 11:52 ` Linus Walleij
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2024-03-11 11:00 UTC (permalink / raw)
To: Linus Walleij
Cc: Bartosz Golaszewski, linux-arm-kernel, linux-gpio, linux-kernel,
kernel-janitors
Using BUG_ON() is discouraged and also the check wasn't done early
enough to prevent an out of bounds access. Check earlier and return
an error instead of calling BUG().
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/gpio/gpio-nomadik.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-nomadik.c b/drivers/gpio/gpio-nomadik.c
index 463a765620dc..5e2f9b51ece3 100644
--- a/drivers/gpio/gpio-nomadik.c
+++ b/drivers/gpio/gpio-nomadik.c
@@ -533,6 +533,11 @@ struct nmk_gpio_chip *nmk_gpio_populate_chip(struct fwnode_handle *fwnode,
}
#ifdef CONFIG_PINCTRL_NOMADIK
+ if (id >= ARRAY_SIZE(nmk_gpio_chips)) {
+ dev_err(dev, "populate: invalid id: %u\n", id);
+ platform_device_put(gpio_pdev);
+ return ERR_PTR(-EINVAL);
+ }
/* Already populated? */
nmk_chip = nmk_gpio_chips[id];
if (nmk_chip) {
@@ -606,7 +611,6 @@ struct nmk_gpio_chip *nmk_gpio_populate_chip(struct fwnode_handle *fwnode,
}
#ifdef CONFIG_PINCTRL_NOMADIK
- BUG_ON(nmk_chip->bank >= ARRAY_SIZE(nmk_gpio_chips));
nmk_gpio_chips[id] = nmk_chip;
#endif
return nmk_chip;
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] gpio: nomadik: remove BUG_ON() in nmk_gpio_populate_chip()
2024-03-11 11:00 [PATCH] gpio: nomadik: remove BUG_ON() in nmk_gpio_populate_chip() Dan Carpenter
@ 2024-03-12 11:52 ` Linus Walleij
2024-03-12 12:14 ` Bartosz Golaszewski
0 siblings, 1 reply; 3+ messages in thread
From: Linus Walleij @ 2024-03-12 11:52 UTC (permalink / raw)
To: Dan Carpenter
Cc: Bartosz Golaszewski, linux-arm-kernel, linux-gpio, linux-kernel,
kernel-janitors
On Mon, Mar 11, 2024 at 12:00 PM Dan Carpenter <dan.carpenter@linaro.org> wrote:
> Using BUG_ON() is discouraged and also the check wasn't done early
> enough to prevent an out of bounds access. Check earlier and return
> an error instead of calling BUG().
>
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Thanks Dan, I applied the patch to the pin control tree since the
rest of the stuff is resting there and Bartosz already sent his pull
request.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gpio: nomadik: remove BUG_ON() in nmk_gpio_populate_chip()
2024-03-12 11:52 ` Linus Walleij
@ 2024-03-12 12:14 ` Bartosz Golaszewski
0 siblings, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2024-03-12 12:14 UTC (permalink / raw)
To: Linus Walleij
Cc: Dan Carpenter, linux-arm-kernel, linux-gpio, linux-kernel,
kernel-janitors
On Tue, Mar 12, 2024 at 12:52 PM Linus Walleij <linus.walleij@linaro.org> wrote:
>
> On Mon, Mar 11, 2024 at 12:00 PM Dan Carpenter <dan.carpenter@linaro.org> wrote:
>
> > Using BUG_ON() is discouraged and also the check wasn't done early
> > enough to prevent an out of bounds access. Check earlier and return
> > an error instead of calling BUG().
> >
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
>
> Thanks Dan, I applied the patch to the pin control tree since the
> rest of the stuff is resting there and Bartosz already sent his pull
> request.
>
Yes I did. There were no conflicts in next with nomadik updates so I
figured you'll just send it yourself. Let me know if you need anything
from my side.
Bart
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-12 12:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-11 11:00 [PATCH] gpio: nomadik: remove BUG_ON() in nmk_gpio_populate_chip() Dan Carpenter
2024-03-12 11:52 ` Linus Walleij
2024-03-12 12:14 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®