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