Skip to content

Commit 7ee1a01

Browse files
baruchsiachbrgl
authored andcommitted
gpio: mvebu: fix potential user-after-free on probe
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>
1 parent 7f57b29 commit 7ee1a01

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

drivers/gpio/gpio-mvebu.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,13 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
11971197

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

1200+
/* Some MVEBU SoCs have simple PWM support for GPIO lines */
1201+
if (IS_ENABLED(CONFIG_PWM)) {
1202+
err = mvebu_pwm_probe(pdev, mvchip, id);
1203+
if (err)
1204+
return err;
1205+
}
1206+
12001207
/* Some gpio controllers do not provide irq support */
12011208
if (!have_irqs)
12021209
return 0;
@@ -1206,7 +1213,8 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
12061213
if (!mvchip->domain) {
12071214
dev_err(&pdev->dev, "couldn't allocate irq domain %s (DT).\n",
12081215
mvchip->chip.label);
1209-
return -ENODEV;
1216+
err = -ENODEV;
1217+
goto err_pwm;
12101218
}
12111219

12121220
err = irq_alloc_domain_generic_chips(
@@ -1254,14 +1262,12 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
12541262
mvchip);
12551263
}
12561264

1257-
/* Some MVEBU SoCs have simple PWM support for GPIO lines */
1258-
if (IS_ENABLED(CONFIG_PWM))
1259-
return mvebu_pwm_probe(pdev, mvchip, id);
1260-
12611265
return 0;
12621266

12631267
err_domain:
12641268
irq_domain_remove(mvchip->domain);
1269+
err_pwm:
1270+
pwmchip_remove(&mvchip->mvpwm->chip);
12651271

12661272
return err;
12671273
}

0 commit comments

Comments
 (0)