* [PATCH] hwrng: imx-rngc - fix runtime PM setup failure
@ 2026-11-29 13:43 Jiawen Liu
2026-11-29 13:57 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Jiawen Liu @ 2026-11-29 13:43 UTC (permalink / raw)
To: Olivia Mackall, Herbert Xu, Frank Li, Sascha Hauer
Cc: Pengutronix Kernel Team, Fabio Estevam, linux-crypto, imx,
linux-arm-kernel, linux-kernel
devm_pm_runtime_enable() can fail after it has rolled runtime PM back to
the disabled state. imx_rngc_probe() ignored that error and continued to
register an RNG whose init callback requires a successful runtime resume.
Hold a temporary runtime PM reference while setting up managed runtime
PM. On failure, drop the reference and unwind the manually enabled clock
before returning. If hwrng registration fails, use pm_runtime_put() so
the managed PM teardown suspends the device and releases the clock
exactly once. Release the reference after successful registration.
Fixes: 7a96a64e8689 ("hwrng: imx-rngc - add runtime pm")
Signed-off-by: Jiawen Liu <1298662399@qq.com>
---
drivers/char/hw_random/imx-rngc.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c
index 8dfd7821225c1..948f3ef9e8d69 100644
--- a/drivers/char/hw_random/imx-rngc.c
+++ b/drivers/char/hw_random/imx-rngc.c
@@ -312,13 +312,21 @@ static int __init imx_rngc_probe(struct platform_device *pdev)
pm_runtime_set_autosuspend_delay(&pdev->dev, RNGC_PM_TIMEOUT);
pm_runtime_use_autosuspend(&pdev->dev);
pm_runtime_set_active(&pdev->dev);
- devm_pm_runtime_enable(&pdev->dev);
+ pm_runtime_get_noresume(&pdev->dev);
+ ret = devm_pm_runtime_enable(&pdev->dev);
+ if (ret) {
+ pm_runtime_put_noidle(&pdev->dev);
+ clk_disable_unprepare(rngc->clk);
+ return dev_err_probe(&pdev->dev, ret,
+ "Failed to enable runtime PM\n");
+ }
ret = devm_hwrng_register(&pdev->dev, &rngc->rng);
if (ret) {
- clk_disable_unprepare(rngc->clk);
+ pm_runtime_put(&pdev->dev);
return dev_err_probe(&pdev->dev, ret, "hwrng registration failed\n");
}
+ pm_runtime_put(&pdev->dev);
dev_info(&pdev->dev,
"Freescale RNG%c registered (HW revision %d.%02d)\n",
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] hwrng: imx-rngc - fix runtime PM setup failure
2026-11-29 13:43 [PATCH] hwrng: imx-rngc - fix runtime PM setup failure Jiawen Liu
@ 2026-11-29 13:57 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-29 13:57 UTC (permalink / raw)
To: Jiawen Liu, Olivia Mackall, Herbert Xu, Frank Li, Sascha Hauer
Cc: Pengutronix Kernel Team, Fabio Estevam, linux-crypto, imx,
Frank.Li
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] hwrng: imx-rngc: clock leak on devm_hwrng_register() error in
imx_rngc_probe()
--
commit a90c66e5122e753cea99f489c48d3ebf74c67153
Author: Jiawen Liu <1298662399@qq.com>
hwrng: imx-rngc - fix runtime PM setup failure
This commit checks the return value of devm_pm_runtime_enable() in
imx_rngc_probe() and holds a temporary runtime PM reference around the
setup and hwrng registration.
> diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c
> index 8dfd7821225c1..948f3ef9e8d69 100644
> --- a/drivers/char/hw_random/imx-rngc.c
> +++ b/drivers/char/hw_random/imx-rngc.c
> @@ -312,13 +312,21 @@ static int __init imx_rngc_probe(struct platform_device *pdev)
> pm_runtime_set_autosuspend_delay(&pdev->dev, RNGC_PM_TIMEOUT);
> pm_runtime_use_autosuspend(&pdev->dev);
> pm_runtime_set_active(&pdev->dev);
> - devm_pm_runtime_enable(&pdev->dev);
> + pm_runtime_get_noresume(&pdev->dev);
> + ret = devm_pm_runtime_enable(&pdev->dev);
> + if (ret) {
> + pm_runtime_put_noidle(&pdev->dev);
> + clk_disable_unprepare(rngc->clk);
> + return dev_err_probe(&pdev->dev, ret,
> + "Failed to enable runtime PM\n");
> + }
>
> ret = devm_hwrng_register(&pdev->dev, &rngc->rng);
> if (ret) {
> - clk_disable_unprepare(rngc->clk);
> + pm_runtime_put(&pdev->dev);
> return dev_err_probe(&pdev->dev, ret, "hwrng registration failed\n");
> }
[Severity: Medium]
Does replacing clk_disable_unprepare(rngc->clk) with pm_runtime_put() leak
rngc->clk when devm_hwrng_register() fails?
imx_rngc_probe() enables rngc->clk manually with clk_prepare_enable() and
relies on imx_rngc_suspend() to disable it during devres teardown. When
CONFIG_PM is disabled, devm_pm_runtime_enable() and pm_runtime_put() are
no-ops and imx_rngc_driver.driver.pm is NULL via pm_ptr(), so
imx_rngc_suspend() never runs and rngc->clk stays prepared and enabled.
Even with CONFIG_PM enabled, pm_runtime_put() only schedules asynchronous
autosuspend. If the autosuspend timer fires and queues RPM_REQ_AUTOSUSPEND
before pm_runtime_disable_action() runs, rpm_idle() in
pm_runtime_dont_use_autosuspend() returns -EAGAIN and pm_runtime_disable()
cancels the pending work item without running imx_rngc_suspend().
--
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_E83A64A52E8D1310A0E3AF63A564FD441106@qq.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-29 13:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 13:43 [PATCH] hwrng: imx-rngc - fix runtime PM setup failure Jiawen Liu
2026-11-29 13:57 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox