From: Guangshuo Li <lgs201920130244@gmail.com>
To: Jia Jie Ho <jiajie.ho@starfivetech.com>,
Olivia Mackall <olivia@selenic.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Philipp Zabel <p.zabel@pengutronix.de>,
Jenny Zhang <jenny.zhang@starfivetech.com>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Guangshuo Li <lgs201920130244@gmail.com>, stable@vger.kernel.org
Subject: [PATCH] hwrng: starfive: fix runtime PM autosuspend cleanup
Date: Sat, 8 Aug 2026 15:25:16 +0800 [thread overview]
Message-ID: <20260808072516.2640658-1-lgs201920130244@gmail.com> (raw)
starfive_trng_probe() calls pm_runtime_use_autosuspend(), but runtime
PM is enabled with pm_runtime_enable() without a corresponding
pm_runtime_dont_use_autosuspend() during driver teardown.
If the autosuspend delay is set to a negative value while autosuspend
is enabled, the runtime PM core increments usage_count to prevent
runtime suspend. Without undoing the autosuspend setting during
teardown, this reference can remain unbalanced.
Use devm_pm_runtime_enable() so that runtime PM and the autosuspend
setting are automatically cleaned up on probe failure and device
removal. Remove the explicit pm_runtime_disable() from the hwrng
registration failure path since the managed cleanup handles it.
This issue was found by manual code inspection.
Fixes: c388f458bc34 ("hwrng: starfive - Add TRNG driver for StarFive SoC")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
drivers/char/hw_random/jh7110-trng.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/char/hw_random/jh7110-trng.c b/drivers/char/hw_random/jh7110-trng.c
index 4712c3c530e4..34b2ec3e13b3 100644
--- a/drivers/char/hw_random/jh7110-trng.c
+++ b/drivers/char/hw_random/jh7110-trng.c
@@ -336,12 +336,18 @@ static int starfive_trng_probe(struct platform_device *pdev)
pm_runtime_use_autosuspend(&pdev->dev);
pm_runtime_set_autosuspend_delay(&pdev->dev, 100);
- pm_runtime_enable(&pdev->dev);
+ ret = devm_pm_runtime_enable(&pdev->dev);
+ if (ret) {
+ reset_control_assert(trng->rst);
+ clk_disable_unprepare(trng->ahb);
+ clk_disable_unprepare(trng->hclk);
+
+ return dev_err_probe(&pdev->dev, ret,
+ "Failed to enable runtime PM\n");
+ }
ret = devm_hwrng_register(&pdev->dev, &trng->rng);
if (ret) {
- pm_runtime_disable(&pdev->dev);
-
reset_control_assert(trng->rst);
clk_disable_unprepare(trng->ahb);
clk_disable_unprepare(trng->hclk);
--
2.43.0
reply other threads:[~2026-08-08 7:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260808072516.2640658-1-lgs201920130244@gmail.com \
--to=lgs201920130244@gmail.com \
--cc=herbert@gondor.apana.org.au \
--cc=jenny.zhang@starfivetech.com \
--cc=jiajie.ho@starfivetech.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=olivia@selenic.com \
--cc=p.zabel@pengutronix.de \
--cc=stable@vger.kernel.org \
/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