diff mbox series

sh: push-switch: Convert to platform remove callback returning void

Message ID 20240306211947.97103-2-u.kleine-koenig@pengutronix.de (mailing list archive)
State New
Headers show
Series sh: push-switch: Convert to platform remove callback returning void | expand

Commit Message

Uwe Kleine-König March 6, 2024, 9:19 p.m. UTC
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 <u.kleine-koenig@pengutronix.de>
---
 arch/sh/drivers/push-switch.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)


base-commit: 11afac187274a6177a7ac82997f8691c0f469e41

Comments

Geert Uytterhoeven March 7, 2024, 8:41 a.m. UTC | #1
On Wed, Mar 6, 2024 at 10:20 PM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> 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 <u.kleine-koenig@pengutronix.de>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert
Uwe Kleine-König April 11, 2024, 7:18 a.m. UTC | #2
Hello,

[corrected the address of the Pengutronix kernel team in Cc:]

On Wed, Mar 06, 2024 at 10:19:47PM +0100, 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.

Apart from Geert's positive review reply I didn't get any feedback on
this patch and it didn't appear in next yet.

As my quest to change the prototype of struct platform_driver::remove
depends on these patches, it would be great if they made it in during
the next merge window.

Best regards
Uwe
John Paul Adrian Glaubitz April 11, 2024, 7:47 a.m. UTC | #3
On Thu, 2024-04-11 at 09:18 +0200, Uwe Kleine-König wrote:
> Apart from Geert's positive review reply I didn't get any feedback on
> this patch and it didn't appear in next yet.

The plan was to get everything approved before merging it for next
as a partial conversion to device tree for SH would probably cause
problems.

Adrian
John Paul Adrian Glaubitz April 11, 2024, 7:49 a.m. UTC | #4
On Thu, 2024-04-11 at 09:47 +0200, John Paul Adrian Glaubitz wrote:
> On Thu, 2024-04-11 at 09:18 +0200, Uwe Kleine-König wrote:
> > Apart from Geert's positive review reply I didn't get any feedback on
> > this patch and it didn't appear in next yet.
> 
> The plan was to get everything approved before merging it for next
> as a partial conversion to device tree for SH would probably cause
> problems.

Oops, sorry. I confused patches here.

I'll pick it up for 6.10.

Adrian
diff mbox series

Patch

diff --git a/arch/sh/drivers/push-switch.c b/arch/sh/drivers/push-switch.c
index 6ecba5f521eb..362e4860bf52 100644
--- a/arch/sh/drivers/push-switch.c
+++ b/arch/sh/drivers/push-switch.c
@@ -91,7 +91,7 @@  static int switch_drv_probe(struct platform_device *pdev)
 	return ret;
 }
 
-static int switch_drv_remove(struct platform_device *pdev)
+static void switch_drv_remove(struct platform_device *pdev)
 {
 	struct push_switch *psw = platform_get_drvdata(pdev);
 	struct push_switch_platform_info *psw_info = pdev->dev.platform_data;
@@ -106,13 +106,11 @@  static int switch_drv_remove(struct platform_device *pdev)
 	free_irq(irq, pdev);
 
 	kfree(psw);
-
-	return 0;
 }
 
 static struct platform_driver switch_driver = {
 	.probe		= switch_drv_probe,
-	.remove		= switch_drv_remove,
+	.remove_new	= switch_drv_remove,
 	.driver		= {
 		.name	= DRV_NAME,
 	},