[PATCH v2 0/6] watchdog: starfive: runtime PM cleanup
From: William Theesfeld
Date: Fri Jun 05 2026 - 09:16:10 EST
The v1 patch was a one-line conversion of pm_runtime_get_sync() to
pm_runtime_resume_and_get() in starfive_wdt_pm_start(). On review,
the StarFive maintainers pointed out one edge case the v1 fix had
missed, plus five pre-existing issues in the surrounding runtime PM
handling that all need to be addressed before the original fix is
useful in practice.
This v2 turns the single fix into a six-patch series. Each patch
addresses one independent issue and can be reviewed in isolation;
they are ordered roughly from the simplest correctness fix to the
ones requiring a small amount of restructuring.
The series:
1/6 Expand the original v1 fix so the runtime PM reference is also
released when starfive_wdt_start() fails after a successful
pm_runtime_resume_and_get().
2/6 Treat a return value of 1 from pm_runtime_put_sync() as success
in both starfive_wdt_pm_stop() and the probe path; the watchdog
framework currently propagates the value verbatim and the probe
takes the err_unregister_wdt path on a non-error return.
3/6 Restructure starfive_wdt_probe() error handling into three
labels (err_pm_disable / err_put_pm / err_unregister_wdt) so
every failure path balances exactly the resources it has
acquired. Previously two early failure paths returned without
calling pm_runtime_disable() and several later paths leaked the
runtime PM reference.
4/6 Gate the system suspend / resume callbacks with
pm_runtime_status_suspended() so the WDOGLOAD / WDOGCONTROL
accesses run only when the device is actually clocked. When
the device was already runtime-suspended the previous code
triggered a synchronous external abort.
5/6 Make starfive_wdt_shutdown() only drop the PM refcount when
WDOG_ACTIVE is set, and stop just the hardware (no PM touch)
when only WDOG_HW_RUNNING is set. This avoids the refcount
underflow that the previous unconditional pm_stop() produced.
6/6 Release the early_enable PM refcount in starfive_wdt_remove()
when WDOG_HW_RUNNING is still asserted at unregister time. The
watchdog framework's stop-on-unregister path only runs the
stop op when WDOG_ACTIVE is set, so the early-enable +
never-opened combination otherwise leaks the probe-time
reference.
The whole series builds cleanly with CONFIG_STARFIVE_WATCHDOG=m on
x86_64 defconfig. Runtime testing would require StarFive JH7100 /
JH7110 hardware and has not been performed.
William Theesfeld (6):
watchdog: starfive: balance PM refcount when start operation fails
watchdog: starfive: treat pm_runtime_put_sync() positive return as
success
watchdog: starfive: balance PM refcount and disable in probe error
paths
watchdog: starfive: guard system suspend/resume hardware access
watchdog: starfive: avoid PM refcount underflow in shutdown
watchdog: starfive: release early_enable PM refcount on remove
drivers/watchdog/starfive-wdt.c | 92 ++++++++++++++++++++++++++-------
1 file changed, 73 insertions(+), 19 deletions(-)
--
2.54.0