Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH] hwrng: omap - fix runtime PM and clock leak on EPROBE_DEFER in probe
@ 2026-09-10 11:24 Peng Hao
  0 siblings, 0 replies; only message in thread
From: Peng Hao @ 2026-09-10 11:24 UTC (permalink / raw)
  To: dsaxena, olivia; +Cc: linux-crypto

omap_rng_probe() calls pm_runtime_enable() and pm_runtime_resume_and_get()
before requesting the optional "reg"/functional clocks. When either
devm_clk_get() returns -EPROBE_DEFER, the probe bails out with a bare
"return -EPROBE_DEFER;", bypassing the err_register cleanup that does
pm_runtime_put_sync() + pm_runtime_disable() (and clk_disable_unprepare()).

As a result every probe deferral leaks a runtime PM usage count and leaves
runtime PM enabled; the next probe attempt then hits an unbalanced
pm_runtime_enable(). The second deferral point additionally leaks the
already-enabled functional clock.

Redirect both -EPROBE_DEFER paths to err_register. clk_disable_unprepare()
is a no-op for the NULL/ERR_PTR clocks on these early paths, so the cleanup
is safe.

Fixes: b166be004491 ("hwrng: omap - Fix clock resource by adding a register clock")
Signed-off-by: Peng Hao <flyingpeng@tencent.com>
---
 drivers/char/hw_random/omap-rng.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c
index 5e8b50f15db7..84e2542c570b 100644
--- a/drivers/char/hw_random/omap-rng.c
+++ b/drivers/char/hw_random/omap-rng.c
@@ -459,8 +459,10 @@ static int omap_rng_probe(struct platform_device *pdev)
 	}
 
 	priv->clk = devm_clk_get(&pdev->dev, NULL);
-	if (PTR_ERR(priv->clk) == -EPROBE_DEFER)
-		return -EPROBE_DEFER;
+	if (PTR_ERR(priv->clk) == -EPROBE_DEFER) {
+		ret = -EPROBE_DEFER;
+		goto err_register;
+	}
 	if (!IS_ERR(priv->clk)) {
 		ret = clk_prepare_enable(priv->clk);
 		if (ret) {
@@ -471,8 +473,10 @@ static int omap_rng_probe(struct platform_device *pdev)
 	}
 
 	priv->clk_reg = devm_clk_get(&pdev->dev, "reg");
-	if (PTR_ERR(priv->clk_reg) == -EPROBE_DEFER)
-		return -EPROBE_DEFER;
+	if (PTR_ERR(priv->clk_reg) == -EPROBE_DEFER) {
+		ret = -EPROBE_DEFER;
+		goto err_register;
+	}
 	if (!IS_ERR(priv->clk_reg)) {
 		ret = clk_prepare_enable(priv->clk_reg);
 		if (ret) {
-- 
2.43.7


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-10 11:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-10 11:24 [PATCH] hwrng: omap - fix runtime PM and clock leak on EPROBE_DEFER in probe Peng Hao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox