Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [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

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