diff mbox series

[01/34] watchdog: s3c2410: Don't skip cleanup in remove's error path

Message ID 20230303213716.2123717-2-u.kleine-koenig@pengutronix.de (mailing list archive)
State New
Headers show
Series watchdog: Convert to platform remove callback returning void | expand

Commit Message

Uwe Kleine-König March 3, 2023, 9:36 p.m. UTC
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(-)

Comments

Guenter Roeck March 4, 2023, 4:58 p.m. UTC | #1
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
diff mbox series

Patch

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);