[PATCH] hwrng: npcm: fix usage_count leak when autosuspend_delay is negative
Guangshuo Li <[email protected]>
| Newsgroups | org.kernel.vger.linux-crypto,org.kernel.vger.linux-kernel,org.kernel.vger.stable,org.ozlabs.lists.openbmc |
|---|---|
| Message-ID | <[email protected]> |
npcm_rng_probe() calls pm_runtime_use_autosuspend(), but neither the
probe failure path nor npcm_rng_remove() calls the matching
pm_runtime_dont_use_autosuspend() before disabling runtime PM.
If the autosuspend delay is set to a negative value while autosuspend
is enabled, the runtime PM core increments usage_count to prevent
runtime suspend. Without calling pm_runtime_dont_use_autosuspend()
during teardown, this reference is not dropped and usage_count remains
unbalanced.
Add the missing pm_runtime_dont_use_autosuspend() calls to both the
probe failure and remove paths before disabling runtime PM.
This issue was found by manual code inspection.
Fixes: c98429297d8b ("hwrng: npcm - add NPCM RNG driver")
Cc: [email protected]
Signed-off-by: Guangshuo Li <[email protected]>
---
drivers/char/hw_random/npcm-rng.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/char/hw_random/npcm-rng.c b/drivers/char/hw_random/npcm-rng.c
index 40d6e29dea03..43f96abee753 100644
--- a/drivers/char/hw_random/npcm-rng.c
+++ b/drivers/char/hw_random/npcm-rng.c
@@ -118,6 +118,7 @@ static int npcm_rng_probe(struct platform_device *pdev)
if (ret) {
dev_err(&pdev->dev, "Failed to register rng device: %d\n",
ret);
+ pm_runtime_dont_use_autosuspend(&pdev->dev);
pm_runtime_disable(&pdev->dev);
pm_runtime_set_suspended(&pdev->dev);
return ret;
@@ -131,6 +132,7 @@ static void npcm_rng_remove(struct platform_device *pdev)
struct npcm_rng *priv = platform_get_drvdata(pdev);
devm_hwrng_unregister(&pdev->dev, &priv->rng);
+ pm_runtime_dont_use_autosuspend(&pdev->dev);
pm_runtime_disable(&pdev->dev);
pm_runtime_set_suspended(&pdev->dev);
}
--
2.43.0