2024-03-08 21:31:43

by Uwe Kleine-König

[permalink] [raw]
Subject: [PATCH 0/2] 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
--
2.43.0



2024-03-08 21:31:50

by Uwe Kleine-König

[permalink] [raw]
Subject: [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.

Signed-off-by: Uwe Kleine-König <[email protected]>
---
drivers/uio/uio_fsl_elbc_gpcm.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/uio/uio_fsl_elbc_gpcm.c b/drivers/uio/uio_fsl_elbc_gpcm.c
index 82dda799f327..496caff66e7e 100644
--- a/drivers/uio/uio_fsl_elbc_gpcm.c
+++ b/drivers/uio/uio_fsl_elbc_gpcm.c
@@ -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);

--
2.43.0


2024-03-08 21:32:06

by Uwe Kleine-König

[permalink] [raw]
Subject: [PATCH 2/2] uio: pruss: 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/uio/uio_pruss.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/uio/uio_pruss.c b/drivers/uio/uio_pruss.c
index 77e2dc404885..fb9f26468ae4 100644
--- a/drivers/uio/uio_pruss.c
+++ b/drivers/uio/uio_pruss.c
@@ -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,
},
--
2.43.0


2024-04-15 07:19:15

by Uwe Kleine-König

[permalink] [raw]
Subject: Re: [PATCH 0/2] uio: Convert to platform remove callback returning void

Hello,

On Fri, Mar 08, 2024 at 10:31:00PM +0100, Uwe Kleine-K?nig wrote:
> 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.
>
> [..]
>
> 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

--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | https://www.pengutronix.de/ |


Attachments:
(No filename) (1.21 kB)
signature.asc (499.00 B)
Download all attachments

2024-04-15 07:32:23

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 0/2] uio: Convert to platform remove callback returning void

On Mon, Apr 15, 2024 at 09:19:00AM +0200, Uwe Kleine-K?nig wrote:
> Hello,
>
> On Fri, Mar 08, 2024 at 10:31:00PM +0100, Uwe Kleine-K?nig wrote:
> > 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.
> >
> > [..]
> >
> > 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

2024-04-15 07:43:03

by Uwe Kleine-König

[permalink] [raw]
Subject: Re: [PATCH 0/2] uio: Convert to platform remove callback returning void

Hello Greg,

On Mon, Apr 15, 2024 at 09:31:35AM +0200, Greg Kroah-Hartman wrote:
> On Mon, Apr 15, 2024 at 09:19:00AM +0200, Uwe Kleine-K?nig wrote:
> > > 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

--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | https://www.pengutronix.de/ |


Attachments:
(No filename) (977.00 B)
signature.asc (499.00 B)
Download all attachments