Commit c1c2a15c authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Bartosz Golaszewski

gpio: grgpio: Fix device removing

If a platform device's remove callback returns non-zero, the device core
emits a warning and still removes the device and calls the devm cleanup
callbacks.

So it's not save to not unregister the gpiochip because on the next request
to a GPIO the driver accesses kfree()'d memory. Also if an IRQ triggers,
the freed memory is accessed.

Instead rely on the GPIO framework to ensure that after gpiochip_remove()
all GPIOs are freed and so the corresponding IRQs are unmapped.

This is a preparation for making platform remove callbacks return void.
Signed-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: default avatarBartosz Golaszewski <brgl@bgdev.pl>
parent 9ca766ea
...@@ -434,25 +434,13 @@ static int grgpio_probe(struct platform_device *ofdev) ...@@ -434,25 +434,13 @@ static int grgpio_probe(struct platform_device *ofdev)
static int grgpio_remove(struct platform_device *ofdev) static int grgpio_remove(struct platform_device *ofdev)
{ {
struct grgpio_priv *priv = platform_get_drvdata(ofdev); struct grgpio_priv *priv = platform_get_drvdata(ofdev);
int i;
int ret = 0;
if (priv->domain) {
for (i = 0; i < GRGPIO_MAX_NGPIO; i++) {
if (priv->uirqs[i].refcnt != 0) {
ret = -EBUSY;
goto out;
}
}
}
gpiochip_remove(&priv->gc); gpiochip_remove(&priv->gc);
if (priv->domain) if (priv->domain)
irq_domain_remove(priv->domain); irq_domain_remove(priv->domain);
out: return 0;
return ret;
} }
static const struct of_device_id grgpio_match[] = { static const struct of_device_id grgpio_match[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment