2024-04-09 09:03:28

by Uwe Kleine-König

[permalink] [raw]
Subject: [PATCH] auxdisplay: seg-led-gpio: Convert to platform remove callback returning void

The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is ignored (apart
from emitting a warning) and this typically results in resource leaks.

To improve here there is a quest to make the remove callback return
void. In the first step of this quest all drivers are converted to
remove_new(), which already returns void. Eventually after all drivers
are converted, .remove_new() will be renamed to .remove().

Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <[email protected]>
---
drivers/auxdisplay/seg-led-gpio.c | 6 ++----

Hello,

the drivers below of drivers/auxdisplay were already converted to struct
platform_driver::remove_new during the v6.9-rc1 development cycle. This
driver was added for v6.9-rc1 still using the old prototype.

There are still more drivers to be converted, so there is from my side
no need to get this into v6.9, but the next merge window would be nice.

Best regards
Uwe
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/auxdisplay/seg-led-gpio.c b/drivers/auxdisplay/seg-led-gpio.c
index 35a8dbb1e9d2..183ab3011cbb 100644
--- a/drivers/auxdisplay/seg-led-gpio.c
+++ b/drivers/auxdisplay/seg-led-gpio.c
@@ -81,14 +81,12 @@ static int seg_led_probe(struct platform_device *pdev)
return linedisp_register(&priv->linedisp, dev, 1, &seg_led_linedisp_ops);
}

-static int seg_led_remove(struct platform_device *pdev)
+static void seg_led_remove(struct platform_device *pdev)
{
struct seg_led_priv *priv = platform_get_drvdata(pdev);

cancel_delayed_work_sync(&priv->work);
linedisp_unregister(&priv->linedisp);
-
- return 0;
}

static const struct of_device_id seg_led_of_match[] = {
@@ -99,7 +97,7 @@ MODULE_DEVICE_TABLE(of, seg_led_of_match);

static struct platform_driver seg_led_driver = {
.probe = seg_led_probe,
- .remove = seg_led_remove,
+ .remove_new = seg_led_remove,
.driver = {
.name = "seg-led-gpio",
.of_match_table = seg_led_of_match,

base-commit: 4cece764965020c22cff7665b18a012006359095
--
2.43.0



2024-04-09 09:29:49

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] auxdisplay: seg-led-gpio: Convert to platform remove callback returning void

On Tue, Apr 9, 2024 at 11:03 AM Uwe Kleine-König
<[email protected]> wrote:
> The .remove() callback for a platform driver returns an int which makes
> many driver authors wrongly assume it's possible to do error handling by
> returning an error code. However the value returned is ignored (apart
> from emitting a warning) and this typically results in resource leaks.
>
> To improve here there is a quest to make the remove callback return
> void. In the first step of this quest all drivers are converted to
> .remove_new(), which already returns void. Eventually after all drivers
> are converted, .remove_new() will be renamed to .remove().
>
> Trivially convert this driver from always returning zero in the remove
> callback to the void returning variant.
>
> Signed-off-by: Uwe Kleine-König <[email protected]>

Reviewed-by: Geert Uytterhoeven <[email protected]>

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68korg

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2024-04-09 12:57:08

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH] auxdisplay: seg-led-gpio: Convert to platform remove callback returning void

On Tue, Apr 09, 2024 at 11:29:06AM +0200, Geert Uytterhoeven wrote:
> On Tue, Apr 9, 2024 at 11:03 AM Uwe Kleine-König
> <[email protected]> wrote:
> > The .remove() callback for a platform driver returns an int which makes
> > many driver authors wrongly assume it's possible to do error handling by
> > returning an error code. However the value returned is ignored (apart
> > from emitting a warning) and this typically results in resource leaks.
> >
> > To improve here there is a quest to make the remove callback return
> > void. In the first step of this quest all drivers are converted to
> > .remove_new(), which already returns void. Eventually after all drivers
> > are converted, .remove_new() will be renamed to .remove().
> >
> > Trivially convert this driver from always returning zero in the remove
> > callback to the void returning variant.
> >
> > Signed-off-by: Uwe Kleine-König <[email protected]>
>
> Reviewed-by: Geert Uytterhoeven <[email protected]>

Pushed to my review and testing queue, thanks!

--
With Best Regards,
Andy Shevchenko



2024-04-09 20:28:48

by Chris Packham

[permalink] [raw]
Subject: Re: [PATCH] auxdisplay: seg-led-gpio: Convert to platform remove callback returning void


On 9/04/24 21:03, Uwe Kleine-König wrote:
> The .remove() callback for a platform driver returns an int which makes
> many driver authors wrongly assume it's possible to do error handling by
> returning an error code. However the value returned is ignored (apart
> from emitting a warning) and this typically results in resource leaks.
>
> To improve here there is a quest to make the remove callback return
> void. In the first step of this quest all drivers are converted to
> .remove_new(), which already returns void. Eventually after all drivers
> are converted, .remove_new() will be renamed to .remove().
>
> Trivially convert this driver from always returning zero in the remove
> callback to the void returning variant.
>
> Signed-off-by: Uwe Kleine-König <[email protected]>

Reviewed-by: Chris Packham <[email protected]>


> ---
> drivers/auxdisplay/seg-led-gpio.c | 6 ++----
>
> Hello,
>
> the drivers below of drivers/auxdisplay were already converted to struct
> platform_driver::remove_new during the v6.9-rc1 development cycle. This
> driver was added for v6.9-rc1 still using the old prototype.
>
> There are still more drivers to be converted, so there is from my side
> no need to get this into v6.9, but the next merge window would be nice.
>
> Best regards
> Uwe
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/auxdisplay/seg-led-gpio.c b/drivers/auxdisplay/seg-led-gpio.c
> index 35a8dbb1e9d2..183ab3011cbb 100644
> --- a/drivers/auxdisplay/seg-led-gpio.c
> +++ b/drivers/auxdisplay/seg-led-gpio.c
> @@ -81,14 +81,12 @@ static int seg_led_probe(struct platform_device *pdev)
> return linedisp_register(&priv->linedisp, dev, 1, &seg_led_linedisp_ops);
> }
>
> -static int seg_led_remove(struct platform_device *pdev)
> +static void seg_led_remove(struct platform_device *pdev)
> {
> struct seg_led_priv *priv = platform_get_drvdata(pdev);
>
> cancel_delayed_work_sync(&priv->work);
> linedisp_unregister(&priv->linedisp);
> -
> - return 0;
> }
>
> static const struct of_device_id seg_led_of_match[] = {
> @@ -99,7 +97,7 @@ MODULE_DEVICE_TABLE(of, seg_led_of_match);
>
> static struct platform_driver seg_led_driver = {
> .probe = seg_led_probe,
> - .remove = seg_led_remove,
> + .remove_new = seg_led_remove,
> .driver = {
> .name = "seg-led-gpio",
> .of_match_table = seg_led_of_match,
>
> base-commit: 4cece764965020c22cff7665b18a012006359095