Linux Watchdog driver development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ivy Lopez" <skunkolee@gmail.com>
Cc: linux-watchdog@vger.kernel.org
Subject: Re: [PATCH v2] watchdog: starfive-wdt: fix PM reference leak in probe error path
Date: Tue, 15 Sep 2026 03:33:05 +0000	[thread overview]
Message-ID: <20260915033305.657481F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260915032032.222665-1-skunkolee@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] pm: desynchronize PM state by manually disabling clocks on put failure
--

commit 5ff7d303ba1caba3e17ed0a2e51c79514ccbc5c5
Author: Ivy Lopez <skunkolee@gmail.com>

watchdog: starfive-wdt: fix PM reference leak in probe error path

This commit addresses a PM reference leak in the probe error path by tracking
whether a PM reference is held and whether clocks are enabled, ensuring they
are properly released on exit.

> diff --git a/drivers/watchdog/starfive-wdt.c b/drivers/watchdog/starfive-wdt.c
> index af55adc4a3c69..4ad587732bdaa 100644
> --- a/drivers/watchdog/starfive-wdt.c
> +++ b/drivers/watchdog/starfive-wdt.c

[ ... ]

> @@ -509,7 +517,12 @@ static int starfive_wdt_probe(struct platform_device *pdev)
>  err_unregister_wdt:
>  	watchdog_unregister_device(&wdt->wdd);
>  err_exit:
> -	starfive_wdt_disable_clock(wdt);
> +	if (pm_ref_held) {
> +		if (pm_runtime_put_sync(&pdev->dev))
> +			starfive_wdt_disable_clock(wdt);

[Severity: High]
Does manually disabling the clock here risk desynchronizing the PM state if
pm_runtime_put_sync() intentionally fails?

If a concurrent operation (like userspace sysfs interaction) bumps the PM
usage count during this window, pm_runtime_put_sync() in starfive_wdt_probe()
returns an error such as -EAGAIN. This indicates the PM core has decided to
keep the device active.

By manually disabling the clocks here, the hardware is turned off while the
PM core still considers the device to be RPM_ACTIVE.

If a concurrent thread or a subsequent driver reprobe accesses the peripheral
registers while unclocked (since a later pm_runtime_resume_and_get() would
find the device already active and skip the resume callback), could this lead
to a bus error or system crash?

> +	} else if (clocks_on) {
> +		starfive_wdt_disable_clock(wdt);
> +	}
>  	pm_runtime_disable(&pdev->dev);
>  
>  	return ret;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260915032032.222665-1-skunkolee@gmail.com?part=1

  reply	other threads:[~2026-09-15  3:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14 16:50 [PATCH] watchdog: starfive-wdt: fix PM reference leak in probe error path Ivy Lopez
2026-09-14 17:03 ` sashiko-bot
2026-09-15  3:20 ` [PATCH v2] " Ivy Lopez
2026-09-15  3:33   ` sashiko-bot [this message]
2026-09-15  3:46   ` Guenter Roeck
2026-09-15  3:49   ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260915033305.657481F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=skunkolee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox