Re: [PATCH v2] watchdog: starfive-wdt: fix PM reference leak in probe error path

From: Guenter Roeck

Date: Mon Sep 14 2026 - 23:46:47 EST


On 9/14/26 20:20, Ivy Lopez wrote:
pm_runtime_resume_and_get() increments the runtime PM usage counter
and, via starfive_wdt_runtime_resume(), enables the clocks. If a
later step in probe() fails (reset_init, clock rate check,
watchdog_start, or watchdog_register_device), control reaches
err_exit, which calls pm_runtime_disable() but never balances the
earlier get, leaking the PM usage count.

Track whether a PM reference is currently held (pm_ref_held) and
whether the clocks are currently enabled (clocks_on), and use them
in err_exit to release exactly what was acquired:

- if a PM reference is held, put it via pm_runtime_put_sync();
only fall back to a manual clock disable if the resulting
suspend transition did not actually run (put failure), since
the runtime_suspend callback already disables the clocks on a
successful put and a redundant call would double-disable them
and underflow the clock enable count.
- if no PM reference is held but the clocks were enabled directly
(runtime PM disabled case), disable them manually.

Also propagate this accounting to the existing pm_runtime_put_sync()
call at the end of a successful probe: its usage-count decrement
happens regardless of the call's return value, so pm_ref_held must
be cleared immediately after calling it to avoid a second,
unbalanced put_sync() call if a later step in that path fails and
falls through to err_exit.

Fixes: db728ea9c7be ("drivers: watchdog: Add StarFive Watchdog driver")
Signed-off-by: Ivy Lopez <skunkolee@xxxxxxxxx>

I really don't get it. People keep sending new patch revisions as response
to previous patch revisions, even though that is discouraged, but no one
admits where they get the idea from.

I am going to just ignore such submissions in the future. Last warning.

Guenter