* [PATCH v2] watchdog: starfive: fix runtime PM usage counter leak in pm_start
@ 2026-08-23 15:44 Manush Prajwal
2026-08-23 16:45 ` Markus Elfring
2026-08-27 13:59 ` Guenter Roeck
0 siblings, 2 replies; 3+ messages in thread
From: Manush Prajwal @ 2026-08-23 15:44 UTC (permalink / raw)
To: xingyu.wu, ziv.xu, wim; +Cc: linux-kernel, linux-watchdog
starfive_wdt_pm_start() calls pm_runtime_get_sync() and returns its
error code directly on failure. Per Documentation/power/runtime_pm.rst,
pm_runtime_get_sync() does not drop the usage counter on error, so the
caller is expected to release the reference itself. The early return
here skips that, leaking a runtime PM usage count on wdd->parent on
every failed resume, which prevents the device from being suspended
correctly afterwards.
Fix it by calling pm_runtime_put_noidle() before returning, mirroring
the same balance the counterpart starfive_wdt_pm_stop() already
maintains with pm_runtime_put_sync().
v1 only balanced the pm_runtime_get_sync() failure path. As Guenter
Roeck and the Sashiko AI review both pointed out, the same leak
remains if the subsequent starfive_wdt_start() call fails: the
runtime PM reference acquired by pm_runtime_get_sync() would still be
held while returning an error, again leaving the device unable to
suspend. Drop the reference on that failure path too.
Signed-off-by: manushprajwal <manushprajwal555@gmail.com>
---
v2: Also drop the pm_runtime reference when starfive_wdt_start() fails,
not just when pm_runtime_get_sync() fails, per Guenter Roeck and
the Sashiko AI review on v1.
drivers/watchdog/starfive-wdt.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/watchdog/starfive-wdt.c b/drivers/watchdog/starfive-wdt.c
index af55adc4a..b1c2d3e4f 100644
--- a/drivers/watchdog/starfive-wdt.c
+++ b/drivers/watchdog/starfive-wdt.c
@@ -373,8 +373,15 @@ static int starfive_wdt_pm_start(struct watchdog_device *wdd)
struct starfive_wdt *wdt = watchdog_get_drvdata(wdd);
int ret = pm_runtime_get_sync(wdd->parent);
- if (ret < 0)
+ if (ret < 0) {
+ pm_runtime_put_noidle(wdd->parent);
return ret;
+ }
- return starfive_wdt_start(wdt);
+ ret = starfive_wdt_start(wdt);
+ if (ret)
+ pm_runtime_put_noidle(wdd->parent);
+
+ return ret;
}
--
2.46.2.windows.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] watchdog: starfive: fix runtime PM usage counter leak in pm_start
2026-08-23 15:44 [PATCH v2] watchdog: starfive: fix runtime PM usage counter leak in pm_start Manush Prajwal
@ 2026-08-23 16:45 ` Markus Elfring
2026-08-27 13:59 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2026-08-23 16:45 UTC (permalink / raw)
To: manushprajwal555, linux-watchdog, Wim Van Sebroeck, Xingyu Wu, Ziv Xu
Cc: LKML
…
> Fix it by calling pm_runtime_put_noidle() before returning, mirroring
> the same balance the counterpart starfive_wdt_pm_stop() already
> maintains with pm_runtime_put_sync().
…
Can a bit of duplicate source code be avoided for the exception handling?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v7.2#n526
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] watchdog: starfive: fix runtime PM usage counter leak in pm_start
2026-08-23 15:44 [PATCH v2] watchdog: starfive: fix runtime PM usage counter leak in pm_start Manush Prajwal
2026-08-23 16:45 ` Markus Elfring
@ 2026-08-27 13:59 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2026-08-27 13:59 UTC (permalink / raw)
To: Manush Prajwal; +Cc: xingyu.wu, ziv.xu, wim, linux-kernel, linux-watchdog
On Sun, Aug 23, 2026 at 09:14:59PM +0530, Manush Prajwal wrote:
> starfive_wdt_pm_start() calls pm_runtime_get_sync() and returns its
> error code directly on failure. Per Documentation/power/runtime_pm.rst,
> pm_runtime_get_sync() does not drop the usage counter on error, so the
> caller is expected to release the reference itself. The early return
> here skips that, leaking a runtime PM usage count on wdd->parent on
> every failed resume, which prevents the device from being suspended
> correctly afterwards.
>
> Fix it by calling pm_runtime_put_noidle() before returning, mirroring
> the same balance the counterpart starfive_wdt_pm_stop() already
> maintains with pm_runtime_put_sync().
>
> v1 only balanced the pm_runtime_get_sync() failure path. As Guenter
> Roeck and the Sashiko AI review both pointed out, the same leak
> remains if the subsequent starfive_wdt_start() call fails: the
> runtime PM reference acquired by pm_runtime_get_sync() would still be
> held while returning an error, again leaving the device unable to
> suspend. Drop the reference on that failure path too.
>
> Signed-off-by: manushprajwal <manushprajwal555@gmail.com>
checkpatch says:
WARNING: From:/Signed-off-by: email name mismatch: 'From: Manush Prajwal <manushprajwal555@gmail.com>' != 'Signed-off-by: manushprajwal <manushprajwal555@gmail.com>'
... which means that I can not apply this patch. Please fix and resend.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-27 13:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-23 15:44 [PATCH v2] watchdog: starfive: fix runtime PM usage counter leak in pm_start Manush Prajwal
2026-08-23 16:45 ` Markus Elfring
2026-08-27 13:59 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®