gpio: mvebu: validate ngpios before use
PATCH v3 1/1 gpio: mvebu: validate ngpios before use
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 <[email protected]>
---
v3: use dev_err_probe
v2: v2: reject higher than 32.
drivers/gpio/gpio-mvebu.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpio/gpio-mvebu.c +3 -0
@@ -1176,6 +1176,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" );
Signature · 1 line
2.55.0