2024-01-10 15:44:46

by Uwe Kleine-König

[permalink] [raw]
Subject: [PATCH 0/7] macintosh: Convert to platform remove callback returning void

Hello,

this series converts all drivers below drivers/macintosh to use
remove_new(). 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.

This is merge window material. All patches are pairwise independent of
each other so they can be applied individually. There isn't a maintainer
for drivers/macintosh, I'm still sending this as a series in the hope
Michael feels repsonsible and applies it completely.

Best regards
Uwe

Uwe Kleine-König (7):
macintosh: therm_windtunnel: Convert to platform remove callback returning void
macintosh: windfarm_pm112: Convert to platform remove callback returning void
macintosh: windfarm_pm121: Convert to platform remove callback returning void
macintosh: windfarm_pm72: Convert to platform remove callback returning void
macintosh: windfarm_pm81: Convert to platform remove callback returning void
macintosh: windfarm_pm91: Convert to platform remove callback returning void
macintosh: windfarm_rm31: Convert to platform remove callback returning void

drivers/macintosh/therm_windtunnel.c | 6 ++----
drivers/macintosh/windfarm_pm112.c | 6 ++----
drivers/macintosh/windfarm_pm121.c | 5 ++---
drivers/macintosh/windfarm_pm72.c | 7 ++-----
drivers/macintosh/windfarm_pm81.c | 8 +++-----
drivers/macintosh/windfarm_pm91.c | 8 +++-----
drivers/macintosh/windfarm_rm31.c | 7 ++-----
7 files changed, 16 insertions(+), 31 deletions(-)

base-commit: 8cb47d7cd090a690c1785385b2f3d407d4a53ad0
--
2.43.0



2024-01-10 15:45:02

by Uwe Kleine-König

[permalink] [raw]
Subject: [PATCH 2/7] macintosh: windfarm_pm112: 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/macintosh/windfarm_pm112.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/macintosh/windfarm_pm112.c b/drivers/macintosh/windfarm_pm112.c
index d1dec314ae30..876b4d8cbe37 100644
--- a/drivers/macintosh/windfarm_pm112.c
+++ b/drivers/macintosh/windfarm_pm112.c
@@ -662,16 +662,14 @@ static int wf_pm112_probe(struct platform_device *dev)
return 0;
}

-static int wf_pm112_remove(struct platform_device *dev)
+static void wf_pm112_remove(struct platform_device *dev)
{
wf_unregister_client(&pm112_events);
- /* should release all sensors and controls */
- return 0;
}

static struct platform_driver wf_pm112_driver = {
.probe = wf_pm112_probe,
- .remove = wf_pm112_remove,
+ .remove_new = wf_pm112_remove,
.driver = {
.name = "windfarm",
},
--
2.43.0


2024-01-10 15:46:22

by Uwe Kleine-König

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

diff --git a/drivers/macintosh/windfarm_pm72.c b/drivers/macintosh/windfarm_pm72.c
index e21f973551cc..14fa1e9ac3e0 100644
--- a/drivers/macintosh/windfarm_pm72.c
+++ b/drivers/macintosh/windfarm_pm72.c
@@ -775,17 +775,14 @@ static int wf_pm72_probe(struct platform_device *dev)
return 0;
}

-static int wf_pm72_remove(struct platform_device *dev)
+static void wf_pm72_remove(struct platform_device *dev)
{
wf_unregister_client(&pm72_events);
-
- /* should release all sensors and controls */
- return 0;
}

static struct platform_driver wf_pm72_driver = {
.probe = wf_pm72_probe,
- .remove = wf_pm72_remove,
+ .remove_new = wf_pm72_remove,
.driver = {
.name = "windfarm",
},
--
2.43.0


2024-01-10 15:48:42

by Uwe Kleine-König

[permalink] [raw]
Subject: [PATCH 1/7] macintosh: therm_windtunnel: 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/macintosh/therm_windtunnel.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/macintosh/therm_windtunnel.c b/drivers/macintosh/therm_windtunnel.c
index 3c1b29476ce2..37cdc6931f6d 100644
--- a/drivers/macintosh/therm_windtunnel.c
+++ b/drivers/macintosh/therm_windtunnel.c
@@ -481,11 +481,9 @@ static int therm_of_probe(struct platform_device *dev)
return -ENODEV;
}

-static int
-therm_of_remove( struct platform_device *dev )
+static void therm_of_remove(struct platform_device *dev)
{
i2c_del_driver( &g4fan_driver );
- return 0;
}

static const struct of_device_id therm_of_match[] = {{
@@ -501,7 +499,7 @@ static struct platform_driver therm_of_driver = {
.of_match_table = therm_of_match,
},
.probe = therm_of_probe,
- .remove = therm_of_remove,
+ .remove_new = therm_of_remove,
};

struct apple_thermal_info {
--
2.43.0


2024-02-15 20:55:35

by Uwe Kleine-König

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

Hello,

On Wed, Jan 10, 2024 at 04:42:47PM +0100, Uwe Kleine-K?nig wrote:
> Hello,
>
> this series converts all drivers below drivers/macintosh to use
> .remove_new(). 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.
>
> This is merge window material. All patches are pairwise independent of
> each other so they can be applied individually. There isn't a maintainer
> for drivers/macintosh, I'm still sending this as a series in the hope
> Michael feels repsonsible and applies it completely.

this didn't happen yet. Michael, is this still on your radar? Or is
there someone more suiteable to take these patches?

Best regards
Uwe

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


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

2024-02-15 22:27:47

by Michael Ellerman

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

Uwe Kleine-König <[email protected]> writes:
> Hello,
>
> On Wed, Jan 10, 2024 at 04:42:47PM +0100, Uwe Kleine-König wrote:
>> Hello,
>>
>> this series converts all drivers below drivers/macintosh to use
>> .remove_new(). 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.
>>
>> This is merge window material. All patches are pairwise independent of
>> each other so they can be applied individually. There isn't a maintainer
>> for drivers/macintosh, I'm still sending this as a series in the hope
>> Michael feels repsonsible and applies it completely.
>
> this didn't happen yet. Michael, is this still on your radar?

Yes, just behind as always. Thanks for the reminder.

cheers

2024-02-20 12:54:36

by Michael Ellerman

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

On Wed, 10 Jan 2024 16:42:47 +0100, Uwe Kleine-König wrote:
> this series converts all drivers below drivers/macintosh to use
> .remove_new(). 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.
>
> This is merge window material. All patches are pairwise independent of
> each other so they can be applied individually. There isn't a maintainer
> for drivers/macintosh, I'm still sending this as a series in the hope
> Michael feels repsonsible and applies it completely.
>
> [...]

Applied to powerpc/next.

[1/7] macintosh: therm_windtunnel: Convert to platform remove callback returning void
https://git.kernel.org/powerpc/c/bd6d99b70b2ffa96119826f22e96a5b77e6f90d6
[2/7] macintosh: windfarm_pm112: Convert to platform remove callback returning void
https://git.kernel.org/powerpc/c/839cf59b5596abcdfbcdc4278a7bd4f8da32e1b2
[3/7] macintosh: windfarm_pm121: Convert to platform remove callback returning void
https://git.kernel.org/powerpc/c/2e7e64c8427c2385bf47456a612d908f827bbbbf
[4/7] macintosh: windfarm_pm72: Convert to platform remove callback returning void
https://git.kernel.org/powerpc/c/057894a40e973c829baacce0b9de6bdf6c8ec1da
[5/7] macintosh: windfarm_pm81: Convert to platform remove callback returning void
https://git.kernel.org/powerpc/c/fb0217d79d77f1092929bae1137ac0f586c29fec
[6/7] macintosh: windfarm_pm91: Convert to platform remove callback returning void
https://git.kernel.org/powerpc/c/7cfe99872c711ffa727db85c608a0897955a2758
[7/7] macintosh: windfarm_rm31: Convert to platform remove callback returning void
https://git.kernel.org/powerpc/c/4b26558415d628ad2c0d3d4ec65156a0c99eaf02

cheers