* [PATCH v2] gpio: grgpio: Fix device removing
@ 2022-06-21 6:40 Uwe Kleine-König
2022-06-21 9:05 ` Andy Shevchenko
2022-06-23 14:42 ` Bartosz Golaszewski
0 siblings, 2 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2022-06-21 6:40 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski; +Cc: linux-gpio, kernel, Andy Shevchenko
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: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Changes since (implicit) v1
(Message-Id: 20220620122933.106035-1-u.kleine-koenig@pengutronix.de):
- Fix capitalisation of GPIO and IRQ in commit log
- Add another "are" in the third paragraph.
- Drop note about a potential bug in GPIO framework
I'm not sure there is actually a bug.
Thanks to Andy Shevchenko for his feedback.
Best regards
Uwe
drivers/gpio/gpio-grgpio.c | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)
diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c
index df563616f943..bea0e32c195d 100644
--- a/drivers/gpio/gpio-grgpio.c
+++ b/drivers/gpio/gpio-grgpio.c
@@ -434,25 +434,13 @@ static int grgpio_probe(struct platform_device *ofdev)
static int grgpio_remove(struct platform_device *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);
if (priv->domain)
irq_domain_remove(priv->domain);
-out:
- return ret;
+ return 0;
}
static const struct of_device_id grgpio_match[] = {
base-commit: f2906aa863381afb0015a9eb7fefad885d4e5a56
--
2.36.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] gpio: grgpio: Fix device removing
2022-06-21 6:40 [PATCH v2] gpio: grgpio: Fix device removing Uwe Kleine-König
@ 2022-06-21 9:05 ` Andy Shevchenko
2022-06-23 14:42 ` Bartosz Golaszewski
1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2022-06-21 9:05 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: Linus Walleij, Bartosz Golaszewski, open list:GPIO SUBSYSTEM,
Sascha Hauer
On Tue, Jun 21, 2022 at 8:40 AM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
>
> 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.
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Changes since (implicit) v1
> (Message-Id: 20220620122933.106035-1-u.kleine-koenig@pengutronix.de):
>
> - Fix capitalisation of GPIO and IRQ in commit log
> - Add another "are" in the third paragraph.
> - Drop note about a potential bug in GPIO framework
> I'm not sure there is actually a bug.
>
> Thanks to Andy Shevchenko for his feedback.
>
> Best regards
> Uwe
>
> drivers/gpio/gpio-grgpio.c | 14 +-------------
> 1 file changed, 1 insertion(+), 13 deletions(-)
>
> diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c
> index df563616f943..bea0e32c195d 100644
> --- a/drivers/gpio/gpio-grgpio.c
> +++ b/drivers/gpio/gpio-grgpio.c
> @@ -434,25 +434,13 @@ static int grgpio_probe(struct platform_device *ofdev)
> static int grgpio_remove(struct platform_device *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);
>
> if (priv->domain)
> irq_domain_remove(priv->domain);
>
> -out:
> - return ret;
> + return 0;
> }
>
> static const struct of_device_id grgpio_match[] = {
>
> base-commit: f2906aa863381afb0015a9eb7fefad885d4e5a56
> --
> 2.36.1
>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] gpio: grgpio: Fix device removing
2022-06-21 6:40 [PATCH v2] gpio: grgpio: Fix device removing Uwe Kleine-König
2022-06-21 9:05 ` Andy Shevchenko
@ 2022-06-23 14:42 ` Bartosz Golaszewski
1 sibling, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2022-06-23 14:42 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: Linus Walleij, open list:GPIO SUBSYSTEM, Sascha Hauer, Andy Shevchenko
On Tue, Jun 21, 2022 at 8:40 AM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
>
> 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: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Changes since (implicit) v1
> (Message-Id: 20220620122933.106035-1-u.kleine-koenig@pengutronix.de):
>
> - Fix capitalisation of GPIO and IRQ in commit log
> - Add another "are" in the third paragraph.
> - Drop note about a potential bug in GPIO framework
> I'm not sure there is actually a bug.
>
> Thanks to Andy Shevchenko for his feedback.
>
> Best regards
> Uwe
>
> drivers/gpio/gpio-grgpio.c | 14 +-------------
> 1 file changed, 1 insertion(+), 13 deletions(-)
>
> diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c
> index df563616f943..bea0e32c195d 100644
> --- a/drivers/gpio/gpio-grgpio.c
> +++ b/drivers/gpio/gpio-grgpio.c
> @@ -434,25 +434,13 @@ static int grgpio_probe(struct platform_device *ofdev)
> static int grgpio_remove(struct platform_device *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);
>
> if (priv->domain)
> irq_domain_remove(priv->domain);
>
> -out:
> - return ret;
> + return 0;
> }
>
> static const struct of_device_id grgpio_match[] = {
>
> base-commit: f2906aa863381afb0015a9eb7fefad885d4e5a56
> --
> 2.36.1
>
Applied, thanks!
Bart
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-23 14:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-21 6:40 [PATCH v2] gpio: grgpio: Fix device removing Uwe Kleine-König
2022-06-21 9:05 ` Andy Shevchenko
2022-06-23 14:42 ` Bartosz Golaszewski
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.