[PATCH v2 6/6] watchdog: starfive: release early_enable PM refcount on remove
From: William Theesfeld
Date: Fri Jun 05 2026 - 09:21:44 EST
When early_enable starts the hardware at probe time, the runtime PM
reference taken by pm_runtime_resume_and_get() is intentionally kept
to hold the device runtime-resumed. In the normal (userspace-opened)
case the watchdog framework unwinds that reference via pm_stop() on
close, and again via stop_on_unregister() during
watchdog_unregister_device().
But watchdog_unregister_device() only runs the stop path when
WDOG_ACTIVE is set (see drivers/watchdog/watchdog_dev.c). If
early_enable started the hardware and userspace never opened it,
WDOG_HW_RUNNING is set without WDOG_ACTIVE: unregister returns
without touching pm_stop, and the probe-time PM reference is leaked.
Drop that reference in starfive_wdt_remove() before
pm_runtime_disable() runs, when WDOG_HW_RUNNING is still asserted.
Signed-off-by: William Theesfeld <william@xxxxxxxxxxxxx>
---
drivers/watchdog/starfive-wdt.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/watchdog/starfive-wdt.c b/drivers/watchdog/starfive-wdt.c
index 848935dc6..d9175b045 100644
--- a/drivers/watchdog/starfive-wdt.c
+++ b/drivers/watchdog/starfive-wdt.c
@@ -538,6 +538,19 @@ static void starfive_wdt_remove(struct platform_device *pdev)
starfive_wdt_stop(wdt);
watchdog_unregister_device(&wdt->wdd);
+ /*
+ * watchdog_unregister_device() only calls our pm_stop op when
+ * WDOG_ACTIVE is set. When early_enable started the hardware at
+ * probe time and userspace never opened the watchdog, the framework
+ * state is WDOG_HW_RUNNING without WDOG_ACTIVE: the unregister path
+ * leaves the runtime PM reference taken at probe outstanding. Drop
+ * it here before disabling runtime PM so the usage counter does not
+ * leak.
+ */
+ if (test_bit(WDOG_HW_RUNNING, &wdt->wdd.status) &&
+ pm_runtime_enabled(&pdev->dev))
+ pm_runtime_put_sync(&pdev->dev);
+
if (pm_runtime_enabled(&pdev->dev))
pm_runtime_disable(&pdev->dev);
else
--
2.54.0