[10/11] firmware: turris-mox-rwtm: Convert to platform remove callback returning void

Message ID 9074d1ad2e889425991fecad664781ae27b2418a.1703693980.git.u.kleine-koenig@pengutronix.de
State New
Headers
Series firmware: Convert to platform remove callback returning void |

Commit Message

Uwe Kleine-König Dec. 27, 2023, 4:26 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>
---
 drivers/firmware/turris-mox-rwtm.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
  

Comments

Marek Behún Dec. 28, 2023, 3:32 p.m. UTC | #1
On Wed, 27 Dec 2023 17:26:34 +0100
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>
> ---
>  drivers/firmware/turris-mox-rwtm.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c
> index 2de0fb139ce1..31d962cdd6eb 100644
> --- a/drivers/firmware/turris-mox-rwtm.c
> +++ b/drivers/firmware/turris-mox-rwtm.c
> @@ -554,7 +554,7 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev)
>  	return ret;
>  }
>  
> -static int turris_mox_rwtm_remove(struct platform_device *pdev)
> +static void turris_mox_rwtm_remove(struct platform_device *pdev)
>  {
>  	struct mox_rwtm *rwtm = platform_get_drvdata(pdev);
>  
> @@ -562,8 +562,6 @@ static int turris_mox_rwtm_remove(struct platform_device *pdev)
>  	sysfs_remove_files(rwtm_to_kobj(rwtm), mox_rwtm_attrs);
>  	kobject_put(rwtm_to_kobj(rwtm));
>  	mbox_free_channel(rwtm->mbox);
> -
> -	return 0;
>  }
>  
>  static const struct of_device_id turris_mox_rwtm_match[] = {
> @@ -576,7 +574,7 @@ MODULE_DEVICE_TABLE(of, turris_mox_rwtm_match);
>  
>  static struct platform_driver turris_mox_rwtm_driver = {
>  	.probe	= turris_mox_rwtm_probe,
> -	.remove	= turris_mox_rwtm_remove,
> +	.remove_new = turris_mox_rwtm_remove,
>  	.driver	= {
>  		.name		= DRIVER_NAME,
>  		.of_match_table	= turris_mox_rwtm_match,

Reviewed-by: Marek Behún <kabel@kernel.org>
  

Patch

diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c
index 2de0fb139ce1..31d962cdd6eb 100644
--- a/drivers/firmware/turris-mox-rwtm.c
+++ b/drivers/firmware/turris-mox-rwtm.c
@@ -554,7 +554,7 @@  static int turris_mox_rwtm_probe(struct platform_device *pdev)
 	return ret;
 }
 
-static int turris_mox_rwtm_remove(struct platform_device *pdev)
+static void turris_mox_rwtm_remove(struct platform_device *pdev)
 {
 	struct mox_rwtm *rwtm = platform_get_drvdata(pdev);
 
@@ -562,8 +562,6 @@  static int turris_mox_rwtm_remove(struct platform_device *pdev)
 	sysfs_remove_files(rwtm_to_kobj(rwtm), mox_rwtm_attrs);
 	kobject_put(rwtm_to_kobj(rwtm));
 	mbox_free_channel(rwtm->mbox);
-
-	return 0;
 }
 
 static const struct of_device_id turris_mox_rwtm_match[] = {
@@ -576,7 +574,7 @@  MODULE_DEVICE_TABLE(of, turris_mox_rwtm_match);
 
 static struct platform_driver turris_mox_rwtm_driver = {
 	.probe	= turris_mox_rwtm_probe,
-	.remove	= turris_mox_rwtm_remove,
+	.remove_new = turris_mox_rwtm_remove,
 	.driver	= {
 		.name		= DRIVER_NAME,
 		.of_match_table	= turris_mox_rwtm_match,