* [PATCHv2] gpio: mvebu: validate ngpios before use
@ 2026-07-08 22:49 Rosen Penev
0 siblings, 0 replies; only message in thread
From: Rosen Penev @ 2026-07-08 22:49 UTC (permalink / raw)
To: linux-gpio
Cc: Linus Walleij, Bartosz Golaszewski, Jason Cooper, Arnd Bergmann,
Thomas Petazzoni, open list
If ngpios is read as 0 from device tree, it is passed via
irq_alloc_domain_generic_chips() as irqs_per_chip, which leads to a
division by zero in DIV_ROUND_UP(d->revmap_size, irqs_per_chip).
Reject ngpios == 0 early.
Also reject higher than 32, which is the limit.
Fixes: fefe7b0923459 ("gpio: introduce gpio-mvebu driver for Marvell SoCs")
Assisted-by: opencode:big-pickle
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v2: reject higher than 32.
drivers/gpio/gpio-mvebu.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index a863b0bf46ff..73f4bbd2a0cd 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -1176,6 +1176,11 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
return -ENODEV;
}
+ if (ngpios == 0 || ngpios > MVEBU_MAX_GPIO_PER_BANK) {
+ dev_err(&pdev->dev, "ngpios must be between 1 and 32\n");
+ return -EINVAL;
+ }
+
id = of_alias_get_id(pdev->dev.of_node, "gpio");
if (id < 0) {
dev_err(&pdev->dev, "Couldn't get OF id\n");
--
2.55.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-07-08 22:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08 22:49 [PATCHv2] gpio: mvebu: validate ngpios before use Rosen Penev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox