Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH v4] gpio: mvebu: validate ngpios before use
@ 2026-11-26  0:26 Rosen Penev
  2026-11-26 14:17 ` Bartosz Golaszewski
  0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-11-26  0:26 UTC (permalink / raw)
  To: linux-gpio
  Cc: Linus Walleij, Bartosz Golaszewski, Jason Cooper, Arnd Bergmann,
	Thomas Petazzoni

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")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 v4: resend
 v3: use dev_err_probe
 v2: reject higher than 32.
 drivers/gpio/gpio-mvebu.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 46604093a01e..f0e8ae657d7f 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -1214,6 +1214,9 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
+	if (ngpios == 0 || ngpios > MVEBU_MAX_GPIO_PER_BANK)
+		return dev_err_probe(&pdev->dev, -EINVAL, "ngpios must be between 1 and 32\n");
+
 	id = of_alias_get_id(pdev->dev.of_node, "gpio");
 	if (id < 0) {
 		dev_err(&pdev->dev, "Couldn't get OF id\n");
-- 
2.56.1


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

* Re: [PATCH v4] gpio: mvebu: validate ngpios before use
  2026-11-26  0:26 [PATCH v4] gpio: mvebu: validate ngpios before use Rosen Penev
@ 2026-11-26 14:17 ` Bartosz Golaszewski
  0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2026-11-26 14:17 UTC (permalink / raw)
  To: linux-gpio, Rosen Penev
  Cc: Bartosz Golaszewski, Linus Walleij, Bartosz Golaszewski,
	Jason Cooper, Arnd Bergmann, Thomas Petazzoni


On Wed, 25 Nov 2026 16:26:50 -0800, Rosen Penev wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/1] gpio: mvebu: validate ngpios before use
      https://git.kernel.org/brgl/c/62a41997c1553b723a7a333c0246d0646ebd2c95

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

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

end of thread, other threads:[~2026-11-26 14:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  0:26 [PATCH v4] gpio: mvebu: validate ngpios before use Rosen Penev
2026-11-26 14:17 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox