[PATCH v2] char: omap-rng: fix runtime PM cleanup

Jiawen Liu posted 1 patch 3 weeks ago
drivers/char/hw_random/omap-rng.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
[PATCH v2] char: omap-rng: fix runtime PM cleanup
Posted by Jiawen Liu 3 weeks ago
omap_rng_probe() enables runtime PM before requesting its optional clocks.
If either devm_clk_get() returns -EPROBE_DEFER, the direct return leaves
the runtime PM usage count elevated and runtime PM enabled. The second
clock lookup can also leave the first clock enabled.

Route each deferred-probe path through resource-matched cleanup. Return
directly after cleanup so normal probe deferrals remain quiet.

Fixes: 43ec540e6f9b ("hwrng: omap - move clock related code to omap_rng_probe()")
Cc: stable@vger.kernel.org
Signed-off-by: Jiawen Liu <1298662399@qq.com>
---
Changes in v2:
- Use the full author name in From and Signed-off-by.
- Return directly after deferred-probe cleanup to keep deferrals quiet.
- Add Fixes and Cc stable tags.

v1: https://lore.kernel.org/all/tencent_1DBD00BAFF365506D40F166D40DEE8F63B0A@qq.com/
Sashiko review: https://sashiko.dev/#/patchset/tencent_1DBD00BAFF365506D40F166D40DEE8F63B0A%40qq.com

 drivers/char/hw_random/omap-rng.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c
index 5e8b50f15db7..c22d70a031e2 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_pm_runtime;
+	}
 	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_pm_runtime_clock_1;
+	}
 	if (!IS_ERR(priv->clk_reg)) {
 		ret = clk_prepare_enable(priv->clk_reg);
 		if (ret) {
@@ -497,6 +501,16 @@ static int omap_rng_probe(struct platform_device *pdev)
 
 	return 0;
 
+err_pm_runtime_clock_1:
+	if (!IS_ERR(priv->clk))
+		clk_disable_unprepare(priv->clk);
+	goto err_pm_runtime;
+
+err_pm_runtime:
+	pm_runtime_put_sync(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+	return ret;
+
 err_register:
 	priv->base = NULL;
 	pm_runtime_put_sync(&pdev->dev);
-- 
2.34.1
Re: [PATCH v2] char: omap-rng: fix runtime PM cleanup
Posted by Herbert Xu 1 week, 2 days ago
On Fri, Sep 04, 2026 at 02:26:54PM +0400, Jiawen Liu wrote:
> omap_rng_probe() enables runtime PM before requesting its optional clocks.
> If either devm_clk_get() returns -EPROBE_DEFER, the direct return leaves
> the runtime PM usage count elevated and runtime PM enabled. The second
> clock lookup can also leave the first clock enabled.
> 
> Route each deferred-probe path through resource-matched cleanup. Return
> directly after cleanup so normal probe deferrals remain quiet.
> 
> Fixes: 43ec540e6f9b ("hwrng: omap - move clock related code to omap_rng_probe()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jiawen Liu <1298662399@qq.com>
> ---
> Changes in v2:
> - Use the full author name in From and Signed-off-by.
> - Return directly after deferred-probe cleanup to keep deferrals quiet.
> - Add Fixes and Cc stable tags.
> 
> v1: https://lore.kernel.org/all/tencent_1DBD00BAFF365506D40F166D40DEE8F63B0A@qq.com/
> Sashiko review: https://sashiko.dev/#/patchset/tencent_1DBD00BAFF365506D40F166D40DEE8F63B0A%40qq.com
> 
>  drivers/char/hw_random/omap-rng.c | 22 ++++++++++++++++++----
>  1 file changed, 18 insertions(+), 4 deletions(-)

Sashiko couldn't apply your patch against linux-next:

https://sashiko.dev/#/patchset/tencent_0D4EB3807DBF6095A7F5A9455D902DBA9708%40qq.com

Please rebase and repost.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt