linux-samsung-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/34] watchdog: Convert to platform remove callback returning void
@ 2023-03-03 21:36 Uwe Kleine-König
  2023-03-03 21:36 ` [PATCH 01/34] watchdog: s3c2410: Don't skip cleanup in remove's error path Uwe Kleine-König
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2023-03-03 21:36 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Wim Van Sebroeck, Guenter Roeck,
	Doug Anderson, Leela Krishna Amudala, Nicolas Ferre,
	Alexandre Belloni, Claudiu Beznea, Florian Fainelli, Ray Jui,
	Scott Branden, Vladimir Zapolskiy, Patrice Chotard,
	Maxime Coquelin, Alexandre Torgue
  Cc: Alim Akhtar, linux-arm-kernel, linux-samsung-soc, linux-watchdog,
	Broadcom internal kernel review list, linux-rpi-kernel,
	linux-stm32, patches, kernel

Hello,

this patch series adapts the platform drivers below drivers/watchdog to
use the .remove_new() callback. Compared to the traditional .remove()
callback .remove_new() returns no value. This is a good thing because
the driver core doesn't (and cannot) cope for errors during remove. The
only effect of a non-zero return value in .remove() is that the driver
core emits a warning. The device is removed anyhow and an early return
from .remove() usually yields a resource leak. One driver suffering from
this problem (s3c2410) is fixed by the first patch.

By changing the remove callback to return void driver authors cannot
reasonably (but wrongly) assume any more that there happens some kind of
cleanup later.

All watchdog drivers but the above mentioned one returned zero
unconditionally in their remove callback, so they could all be converted
trivially to .remove_new().

Note that this series depends on commit 5c5a7680e67b ("platform: Provide
a remove callback that returns no value") that is already in Linus' tree
but not yet included in a tagged version.

Best regards
Uwe

Uwe Kleine-König (34):
  watchdog: s3c2410: Don't skip cleanup in remove's error path
  watchdog: acquirewdt: Convert to platform remove callback returning void
  watchdog: advantechwdt: Convert to platform remove callback returning void
  watchdog: ar7: Convert to platform remove callback returning void
  watchdog: at91rm9200: Convert to platform remove callback returning void
  watchdog: ath79: Convert to platform remove callback returning void
  watchdog: bcm2835: Convert to platform remove callback returning void
  watchdog: bcm47xx: Convert to platform remove callback returning void
  watchdog: bcm_kona: Convert to platform remove callback returning void
  watchdog: cpwd: Convert to platform remove callback returning void
  watchdog: dw: Convert to platform remove callback returning void
  watchdog: gef: Convert to platform remove callback returning void
  watchdog: geodewdt: Convert to platform remove callback returning void
  watchdog: ib700wdt: Convert to platform remove callback returning void
  watchdog: ie6xx: Convert to platform remove callback returning void
  watchdog: lpc18xx: Convert to platform remove callback returning void
  watchdog: mtx-1: Convert to platform remove callback returning void
  watchdog: nic7018: Convert to platform remove callback returning void
  watchdog: nv_tco: Convert to platform remove callback returning void
  watchdog: omap: Convert to platform remove callback returning void
  watchdog: orion: Convert to platform remove callback returning void
  watchdog: rc32434: Convert to platform remove callback returning void
  watchdog: rdc321x: Convert to platform remove callback returning void
  watchdog: renesas: Convert to platform remove callback returning void
  watchdog: riowd: Convert to platform remove callback returning void
  watchdog: rn5t618: Convert to platform remove callback returning void
  watchdog: rti: Convert to platform remove callback returning void
  watchdog: s3c2410: Convert to platform remove callback returning void
  watchdog: sa1100: Convert to platform remove callback returning void
  watchdog: sch311x: Convert to platform remove callback returning void
  watchdog: shwdt: Convert to platform remove callback returning void
  watchdog: st_lpc: Convert to platform remove callback returning void
  watchdog: stmp3xxx_rtc: Convert to platform remove callback returning void
  watchdog: wm8350: Convert to platform remove callback returning void

 drivers/watchdog/acquirewdt.c       | 6 ++----
 drivers/watchdog/advantechwdt.c     | 6 ++----
 drivers/watchdog/ar7_wdt.c          | 5 ++---
 drivers/watchdog/at91rm9200_wdt.c   | 6 ++----
 drivers/watchdog/ath79_wdt.c        | 5 ++---
 drivers/watchdog/bcm2835_wdt.c      | 6 ++----
 drivers/watchdog/bcm47xx_wdt.c      | 6 ++----
 drivers/watchdog/bcm_kona_wdt.c     | 6 ++----
 drivers/watchdog/cpwd.c             | 6 ++----
 drivers/watchdog/dw_wdt.c           | 6 ++----
 drivers/watchdog/gef_wdt.c          | 6 ++----
 drivers/watchdog/geodewdt.c         | 5 ++---
 drivers/watchdog/ib700wdt.c         | 5 ++---
 drivers/watchdog/ie6xx_wdt.c        | 6 ++----
 drivers/watchdog/lpc18xx_wdt.c      | 6 ++----
 drivers/watchdog/mtx-1_wdt.c        | 5 ++---
 drivers/watchdog/nic7018_wdt.c      | 6 ++----
 drivers/watchdog/nv_tco.c           | 6 ++----
 drivers/watchdog/omap_wdt.c         | 6 ++----
 drivers/watchdog/orion_wdt.c        | 5 ++---
 drivers/watchdog/rc32434_wdt.c      | 5 ++---
 drivers/watchdog/rdc321x_wdt.c      | 6 ++----
 drivers/watchdog/renesas_wdt.c      | 6 ++----
 drivers/watchdog/riowd.c            | 6 ++----
 drivers/watchdog/rn5t618_wdt.c      | 6 ++----
 drivers/watchdog/rti_wdt.c          | 6 ++----
 drivers/watchdog/s3c2410_wdt.c      | 9 ++++-----
 drivers/watchdog/sa1100_wdt.c       | 6 ++----
 drivers/watchdog/sch311x_wdt.c      | 5 ++---
 drivers/watchdog/shwdt.c            | 6 ++----
 drivers/watchdog/st_lpc_wdt.c       | 6 ++----
 drivers/watchdog/stmp3xxx_rtc_wdt.c | 5 ++---
 drivers/watchdog/wm8350_wdt.c       | 5 ++---
 33 files changed, 68 insertions(+), 123 deletions(-)

base-commit: 2eb29d59ddf02e39774abfb60b2030b0b7e27c1f
-- 
2.39.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 01/34] watchdog: s3c2410: Don't skip cleanup in remove's error path
  2023-03-03 21:36 [PATCH 00/34] watchdog: Convert to platform remove callback returning void Uwe Kleine-König
@ 2023-03-03 21:36 ` Uwe Kleine-König
  2023-03-04 16:58   ` Guenter Roeck
  2023-03-03 21:37 ` [PATCH 28/34] watchdog: s3c2410: Convert to platform remove callback returning void Uwe Kleine-König
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Uwe Kleine-König @ 2023-03-03 21:36 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Wim Van Sebroeck, Guenter Roeck,
	Doug Anderson, Leela Krishna Amudala
  Cc: Alim Akhtar, linux-arm-kernel, linux-samsung-soc, linux-watchdog, kernel

Returning early in a platform driver's remove callback is wrong. In this
case the watchdog device is never removed although it's parent is gone
which likely can trigger a use-after-free in sysfs. Also the two used
clocks will never be disabled.

Instead only warn if s3c2410wdt_enable() fails and cleanup. Note that
returning 0 is the right thing to do then to suppress another warning
message by the driver core.

Fixes: 4f1f653a68d6 ("watchdog: s3c2410_wdt: use syscon regmap interface to configure pmu register")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/watchdog/s3c2410_wdt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
index 200ba236a72e..cf104a844a43 100644
--- a/drivers/watchdog/s3c2410_wdt.c
+++ b/drivers/watchdog/s3c2410_wdt.c
@@ -782,7 +782,8 @@ static int s3c2410wdt_remove(struct platform_device *dev)
 
 	ret = s3c2410wdt_enable(wdt, false);
 	if (ret < 0)
-		return ret;
+		dev_warn(&dev->dev,
+			 "Failed to disable watchdog (%pe)\n", ERR_PTR(ret));
 
 	watchdog_unregister_device(&wdt->wdt_device);
 
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 28/34] watchdog: s3c2410: Convert to platform remove callback returning void
  2023-03-03 21:36 [PATCH 00/34] watchdog: Convert to platform remove callback returning void Uwe Kleine-König
  2023-03-03 21:36 ` [PATCH 01/34] watchdog: s3c2410: Don't skip cleanup in remove's error path Uwe Kleine-König
@ 2023-03-03 21:37 ` Uwe Kleine-König
  2023-03-04 17:12   ` Guenter Roeck
  2023-03-06 17:05 ` [PATCH 00/34] watchdog: " Uwe Kleine-König
  2023-03-14  8:38 ` Naresh Kamboju
  3 siblings, 1 reply; 7+ messages in thread
From: Uwe Kleine-König @ 2023-03-03 21:37 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Wim Van Sebroeck, Guenter Roeck
  Cc: Alim Akhtar, linux-arm-kernel, linux-samsung-soc, linux-watchdog, kernel

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 (mostly) ignored
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.

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/watchdog/s3c2410_wdt.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
index cf104a844a43..d1f408913843 100644
--- a/drivers/watchdog/s3c2410_wdt.c
+++ b/drivers/watchdog/s3c2410_wdt.c
@@ -775,7 +775,7 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
 	return ret;
 }
 
-static int s3c2410wdt_remove(struct platform_device *dev)
+static void s3c2410wdt_remove(struct platform_device *dev)
 {
 	int ret;
 	struct s3c2410_wdt *wdt = platform_get_drvdata(dev);
@@ -789,8 +789,6 @@ static int s3c2410wdt_remove(struct platform_device *dev)
 
 	clk_disable_unprepare(wdt->src_clk);
 	clk_disable_unprepare(wdt->bus_clk);
-
-	return 0;
 }
 
 static void s3c2410wdt_shutdown(struct platform_device *dev)
@@ -845,7 +843,7 @@ static DEFINE_SIMPLE_DEV_PM_OPS(s3c2410wdt_pm_ops,
 
 static struct platform_driver s3c2410wdt_driver = {
 	.probe		= s3c2410wdt_probe,
-	.remove		= s3c2410wdt_remove,
+	.remove_new	= s3c2410wdt_remove,
 	.shutdown	= s3c2410wdt_shutdown,
 	.id_table	= s3c2410_wdt_ids,
 	.driver		= {
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 01/34] watchdog: s3c2410: Don't skip cleanup in remove's error path
  2023-03-03 21:36 ` [PATCH 01/34] watchdog: s3c2410: Don't skip cleanup in remove's error path Uwe Kleine-König
@ 2023-03-04 16:58   ` Guenter Roeck
  0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2023-03-04 16:58 UTC (permalink / raw)
  To: Uwe Kleine-König, Krzysztof Kozlowski, Wim Van Sebroeck,
	Doug Anderson, Leela Krishna Amudala
  Cc: Alim Akhtar, linux-arm-kernel, linux-samsung-soc, linux-watchdog, kernel

Hi Uwe,

On 3/3/23 13:36, Uwe Kleine-König wrote:
> Returning early in a platform driver's remove callback is wrong. In this
> case the watchdog device is never removed although it's parent is gone
> which likely can trigger a use-after-free in sysfs. Also the two used
> clocks will never be disabled.
> 
> Instead only warn if s3c2410wdt_enable() fails and cleanup. Note that
> returning 0 is the right thing to do then to suppress another warning
> message by the driver core.
> 
> Fixes: 4f1f653a68d6 ("watchdog: s3c2410_wdt: use syscon regmap interface to configure pmu register")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>   drivers/watchdog/s3c2410_wdt.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
> index 200ba236a72e..cf104a844a43 100644
> --- a/drivers/watchdog/s3c2410_wdt.c
> +++ b/drivers/watchdog/s3c2410_wdt.c
> @@ -782,7 +782,8 @@ static int s3c2410wdt_remove(struct platform_device *dev)
>   
>   	ret = s3c2410wdt_enable(wdt, false);
>   	if (ret < 0)
> -		return ret;
> +		dev_warn(&dev->dev,
> +			 "Failed to disable watchdog (%pe)\n", ERR_PTR(ret));
>   
>   	watchdog_unregister_device(&wdt->wdt_device);
>   

I sent out two patches a minute ago which should make this patch
as well as the use of the remove_new callback unnecessary.

Guenter


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 28/34] watchdog: s3c2410: Convert to platform remove callback returning void
  2023-03-03 21:37 ` [PATCH 28/34] watchdog: s3c2410: Convert to platform remove callback returning void Uwe Kleine-König
@ 2023-03-04 17:12   ` Guenter Roeck
  0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2023-03-04 17:12 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Krzysztof Kozlowski, Wim Van Sebroeck, Alim Akhtar,
	linux-arm-kernel, linux-samsung-soc, linux-watchdog, kernel

On Fri, Mar 03, 2023 at 10:37:10PM +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 (mostly) ignored
> 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.
> 
> 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>

Should no longer be necessary with the two patches I sent a short
time ago.

Guenter

> ---
>  drivers/watchdog/s3c2410_wdt.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
> index cf104a844a43..d1f408913843 100644
> --- a/drivers/watchdog/s3c2410_wdt.c
> +++ b/drivers/watchdog/s3c2410_wdt.c
> @@ -775,7 +775,7 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
>  	return ret;
>  }
>  
> -static int s3c2410wdt_remove(struct platform_device *dev)
> +static void s3c2410wdt_remove(struct platform_device *dev)
>  {
>  	int ret;
>  	struct s3c2410_wdt *wdt = platform_get_drvdata(dev);
> @@ -789,8 +789,6 @@ static int s3c2410wdt_remove(struct platform_device *dev)
>  
>  	clk_disable_unprepare(wdt->src_clk);
>  	clk_disable_unprepare(wdt->bus_clk);
> -
> -	return 0;
>  }
>  
>  static void s3c2410wdt_shutdown(struct platform_device *dev)
> @@ -845,7 +843,7 @@ static DEFINE_SIMPLE_DEV_PM_OPS(s3c2410wdt_pm_ops,
>  
>  static struct platform_driver s3c2410wdt_driver = {
>  	.probe		= s3c2410wdt_probe,
> -	.remove		= s3c2410wdt_remove,
> +	.remove_new	= s3c2410wdt_remove,
>  	.shutdown	= s3c2410wdt_shutdown,
>  	.id_table	= s3c2410_wdt_ids,
>  	.driver		= {
> -- 
> 2.39.1
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 00/34] watchdog: Convert to platform remove callback returning void
  2023-03-03 21:36 [PATCH 00/34] watchdog: Convert to platform remove callback returning void Uwe Kleine-König
  2023-03-03 21:36 ` [PATCH 01/34] watchdog: s3c2410: Don't skip cleanup in remove's error path Uwe Kleine-König
  2023-03-03 21:37 ` [PATCH 28/34] watchdog: s3c2410: Convert to platform remove callback returning void Uwe Kleine-König
@ 2023-03-06 17:05 ` Uwe Kleine-König
  2023-03-14  8:38 ` Naresh Kamboju
  3 siblings, 0 replies; 7+ messages in thread
From: Uwe Kleine-König @ 2023-03-06 17:05 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Wim Van Sebroeck, Guenter Roeck,
	Doug Anderson, Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
	Florian Fainelli, Ray Jui, Scott Branden, Vladimir Zapolskiy,
	Patrice Chotard, Maxime Coquelin, Alexandre Torgue
  Cc: kernel, linux-samsung-soc, linux-watchdog, patches,
	Broadcom internal kernel review list, linux-rpi-kernel,
	Alim Akhtar, linux-stm32, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 2040 bytes --]

Hello,

[dropping Leela Krishna Amudala from the list of recipents as their
email address bounces]

On Fri, Mar 03, 2023 at 10:36:42PM +0100, Uwe Kleine-König wrote:
> this patch series adapts the platform drivers below drivers/watchdog to
> use the .remove_new() callback. Compared to the traditional .remove()
> callback .remove_new() returns no value. This is a good thing because
> the driver core doesn't (and cannot) cope for errors during remove. The
> only effect of a non-zero return value in .remove() is that the driver
> core emits a warning. The device is removed anyhow and an early return
> from .remove() usually yields a resource leak. One driver suffering from
> this problem (s3c2410) is fixed by the first patch.
> 
> By changing the remove callback to return void driver authors cannot
> reasonably (but wrongly) assume any more that there happens some kind of
> cleanup later.
> 
> All watchdog drivers but the above mentioned one returned zero
> unconditionally in their remove callback, so they could all be converted
> trivially to .remove_new().
> 
> Note that this series depends on commit 5c5a7680e67b ("platform: Provide
> a remove callback that returns no value") that is already in Linus' tree
> but not yet included in a tagged version.

This is fixed now, v6.3-rc1 is suitable as a base for this series.

Guenter pointed out that for some drivers it is possible to make use of
devm_watchdog_register_device() and drop the remove callback completely.
Also there is an alternative series that gets rid of s3c2410's remove
callback.

I'll send out a series converting the three drivers to
devm_watchdog_register_device() as Guenter suggested. To apply the
remainder of this series you might want to do:

	b4 am -l -P 2-7,9-25,27,29-33 20230303213716.2123717-1-u.kleine-koenig@pengutronix.de

Best regards
Uwe

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 00/34] watchdog: Convert to platform remove callback returning void
  2023-03-03 21:36 [PATCH 00/34] watchdog: Convert to platform remove callback returning void Uwe Kleine-König
                   ` (2 preceding siblings ...)
  2023-03-06 17:05 ` [PATCH 00/34] watchdog: " Uwe Kleine-König
@ 2023-03-14  8:38 ` Naresh Kamboju
  3 siblings, 0 replies; 7+ messages in thread
From: Naresh Kamboju @ 2023-03-14  8:38 UTC (permalink / raw)
  To: u.kleine-koenig
  Cc: alexandre.belloni, alexandre.torgue, alim.akhtar,
	bcm-kernel-feedback-list, claudiu.beznea, dianders, f.fainelli,
	kernel, krzysztof.kozlowski, leela.krishna, linux-arm-kernel,
	linux-rpi-kernel, linux-samsung-soc, linux-stm32, linux-watchdog,
	linux, mcoquelin.stm32, nicolas.ferre, patches, patrice.chotard,
	rjui, sbranden, vz, wim, Linux Kernel Functional Testing


> Hello,
> 
> this patch series adapts the platform drivers below drivers/watchdog to
> use the .remove_new() callback. Compared to the traditional .remove()
> callback .remove_new() returns no value. This is a good thing because
> the driver core doesn't (and cannot) cope for errors during remove. The
> only effect of a non-zero return value in .remove() is that the driver
> core emits a warning. The device is removed anyhow and an early return
> from .remove() usually yields a resource leak. One driver suffering from
> this problem (s3c2410) is fixed by the first patch.

This patch set applied on top of Linux next.

Build tested with gcc-12, clang-16 and clang nightly.
Boot and LTP smoketests performed on
 - qemu-x86_64
 - qemu-arm64
 - fvp-aemva
 - qemu-armv7
 - qemu-i386

Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>

--
Linaro LKFT
https://lkft.linaro.org

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-03-14  8:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-03 21:36 [PATCH 00/34] watchdog: Convert to platform remove callback returning void Uwe Kleine-König
2023-03-03 21:36 ` [PATCH 01/34] watchdog: s3c2410: Don't skip cleanup in remove's error path Uwe Kleine-König
2023-03-04 16:58   ` Guenter Roeck
2023-03-03 21:37 ` [PATCH 28/34] watchdog: s3c2410: Convert to platform remove callback returning void Uwe Kleine-König
2023-03-04 17:12   ` Guenter Roeck
2023-03-06 17:05 ` [PATCH 00/34] watchdog: " Uwe Kleine-König
2023-03-14  8:38 ` Naresh Kamboju

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).