[PATCH] hwrng: imx-rngc - fix runtime PM setup failure
From: Jiawen Liu
Date: Sun Nov 29 2026 - 08:43:56 EST
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@xxxxxx>
---
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