Skip to content

Commit

Permalink
gpio: mvebu: fix potential user-after-free on probe
Browse files Browse the repository at this point in the history
[ Upstream commit 7ee1a01 ]

When mvebu_pwm_probe() fails IRQ domain is not released. Move pwm probe
before IRQ domain allocation. Add pwm cleanup code to the failure path.

Fixes: 757642f ("gpio: mvebu: Add limited PWM support")
Reported-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
baruchsiach authored and gregkh committed Dec 30, 2020
1 parent ec64dea commit e190d1b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions drivers/gpio/gpio-mvebu.c
Expand Up @@ -1196,6 +1196,13 @@ static int mvebu_gpio_probe(struct platform_device *pdev)

devm_gpiochip_add_data(&pdev->dev, &mvchip->chip, mvchip);

/* Some MVEBU SoCs have simple PWM support for GPIO lines */
if (IS_ENABLED(CONFIG_PWM)) {
err = mvebu_pwm_probe(pdev, mvchip, id);
if (err)
return err;
}

/* Some gpio controllers do not provide irq support */
if (!have_irqs)
return 0;
Expand All @@ -1205,7 +1212,8 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
if (!mvchip->domain) {
dev_err(&pdev->dev, "couldn't allocate irq domain %s (DT).\n",
mvchip->chip.label);
return -ENODEV;
err = -ENODEV;
goto err_pwm;
}

err = irq_alloc_domain_generic_chips(
Expand Down Expand Up @@ -1253,14 +1261,12 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
mvchip);
}

/* Some MVEBU SoCs have simple PWM support for GPIO lines */
if (IS_ENABLED(CONFIG_PWM))
return mvebu_pwm_probe(pdev, mvchip, id);

return 0;

err_domain:
irq_domain_remove(mvchip->domain);
err_pwm:
pwmchip_remove(&mvchip->mvpwm->chip);

return err;
}
Expand Down

0 comments on commit e190d1b

Please sign in to comment.