Skip to contentSkip to conversation

uio: Convert to platform remove callback returning void

PATCH In review Uwe Kleine-König 2 participants 6 messages Mar 8, 2024 – Apr 15, 2024 Userspace I/O (UIO)

lore
Share & tools
lore
#0 lore raw

cover uio: Convert to platform remove callback returning void

Hello,

this series converts the two platform drivers below drivers/uio that make use of .remove() to use .remove_new() instead.

See commit 5c5a7680e67b ("platform: Provide a remove callback that returns no value") for an extended explanation and the eventual goal. The TL;DR; is to make it harder for driver authors to leak resources without noticing. The drivers here get it right though and so can be converted trivially.

This is merge window material. The two patches are independent of each other so they can be applied individually if necessary. But I assume and suggest that Greg will pick them up together.

Best regards
Uwe

Uwe Kleine-König (2):
uio: fsl_elbc_gpcm: Convert to platform remove callback returning void
uio: pruss: Convert to platform remove callback returning void

 drivers/uio/uio_fsl_elbc_gpcm.c | 6 ++----
 drivers/uio/uio_pruss.c         | 5 ++---
 2 files changed, 4 insertions(+), 7 deletions(-)

base-commit: 8ffc8b1bbd505e27e2c8439d326b6059c906c9dd

Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 uio: fsl_elbc_gpcm: 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.

---
 drivers/uio/uio_fsl_elbc_gpcm.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/uio/uio_fsl_elbc_gpcm.c +2 -4
index 82dda799f327..496caff66e7e 100644
@@ -427,7 +427,7 @@ static int uio_fsl_elbc_gpcm_probe(struct platform_device *pdev)
 	return ret;
 }
 
-static int uio_fsl_elbc_gpcm_remove(struct platform_device *pdev)
+static void uio_fsl_elbc_gpcm_remove(struct platform_device *pdev)
 {
 	struct uio_info *info = platform_get_drvdata(pdev);
 	struct fsl_elbc_gpcm *priv = info->priv;
@@ -438,8 +438,6 @@ static int uio_fsl_elbc_gpcm_remove(struct platform_device *pdev)
 		priv->shutdown(info, false);
 	iounmap(info->mem[0].internal_addr);
 
-	return 0;
-
 }
 
 static const struct of_device_id uio_fsl_elbc_gpcm_match[] = {
@@ -455,7 +453,7 @@ static struct platform_driver uio_fsl_elbc_gpcm_driver = {
 		.dev_groups = uio_fsl_elbc_gpcm_groups,
 	},
 	.probe = uio_fsl_elbc_gpcm_probe,
-	.remove = uio_fsl_elbc_gpcm_remove,
+	.remove_new = uio_fsl_elbc_gpcm_remove,
 };
 module_platform_driver(uio_fsl_elbc_gpcm_driver);
 
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/2 uio: pruss: Convert to platform remove callback returning void

In reply to Uwe Kleine-König

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.

---
 drivers/uio/uio_pruss.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/uio/uio_pruss.c +2 -3
index 77e2dc404885..fb9f26468ae4 100644
@@ -229,17 +229,16 @@ static int pruss_probe(struct platform_device *pdev)
 	return ret;
 }
 
-static int pruss_remove(struct platform_device *dev)
+static void pruss_remove(struct platform_device *dev)
 {
 	struct uio_pruss_dev *gdev = platform_get_drvdata(dev);
 
 	pruss_cleanup(&dev->dev, gdev);
-	return 0;
 }
 
 static struct platform_driver pruss_driver = {
 	.probe = pruss_probe,
-	.remove = pruss_remove,
+	.remove_new = pruss_remove,
 	.driver = {
 		   .name = DRV_NAME,
 		   },
Signature · 1 line
2.43.0
#3 lore raw
In reply to Uwe Kleine-König

Hello,

Quoted 13 lines · Uwe Kleine-König

this series converts the two platform drivers below drivers/uio that make use of .remove() to use .remove_new() instead.

See commit 5c5a7680e67b ("platform: Provide a remove callback that returns no value") for an extended explanation and the eventual goal. The TL;DR; is to make it harder for driver authors to leak resources without noticing. The drivers here get it right though and so can be converted trivially.

This is merge window material. The two patches are independent of each other so they can be applied individually if necessary. But I assume and suggest that Greg will pick them up together.

Quoted 5 lines

[..]

Uwe Kleine-König (2):
uio: fsl_elbc_gpcm: Convert to platform remove callback returning void
uio: pruss: Convert to platform remove callback returning void

The commit 1019fa4839c9 ("uio: pruss: Remove this driver") (currently in next) makes the pruss patch obsolete. The fsl_elbc_gpcm patch was applied.

Thanks
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
#4 lore raw
Quoted 18 lines · Uwe Kleine-König

Hello,

Quoted 15 lines · Uwe Kleine-König

this series converts the two platform drivers below drivers/uio that make use of .remove() to use .remove_new() instead.

See commit 5c5a7680e67b ("platform: Provide a remove callback that returns no value") for an extended explanation and the eventual goal. The TL;DR; is to make it harder for driver authors to leak resources without noticing. The drivers here get it right though and so can be converted trivially.

This is merge window material. The two patches are independent of each other so they can be applied individually if necessary. But I assume and suggest that Greg will pick them up together.

[..]

Quoted 7 lines
Quoted 3 lines

Uwe Kleine-König (2):
uio: fsl_elbc_gpcm: Convert to platform remove callback returning void
uio: pruss: Convert to platform remove callback returning void

The commit 1019fa4839c9 ("uio: pruss: Remove this driver") (currently in next) makes the pruss patch obsolete. The fsl_elbc_gpcm patch was applied.

Yes, that's why I only applied one, sorry if I didn't let you know.

greg k-h

#5 lore raw

Hello Greg,

Quoted 10 lines · Greg Kroah-Hartman
Quoted 7 lines · Uwe Kleine-König
Quoted 3 lines

Uwe Kleine-König (2):
uio: fsl_elbc_gpcm: Convert to platform remove callback returning void
uio: pruss: Convert to platform remove callback returning void

The commit 1019fa4839c9 ("uio: pruss: Remove this driver") (currently in next) makes the pruss patch obsolete. The fsl_elbc_gpcm patch was applied.

Yes, that's why I only applied one, sorry if I didn't let you know.

Everything's fine on my end. Given I monitor next now with the goal to change struct platform_driver::remove after the upcoming merge window, I noticed myself. My message was only informational, no blame intended.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |