Message ID | 20201130130118.51339-1-miaoqinglang@huawei.com |
---|---|
State | New |
Headers | show |
Series | [v2] hwrng: exynos - fix reference leak in exynos_trng_probe | expand |
It was <2020-11-30 pon 21:01>, when Qinglang Miao wrote: > pm_runtime_get_sync will increment pm usage counter even > failed. Forgetting to putting operation will result in a > reference leak here. > > Replace it with pm_runtime_resume_and_get to keep usage > counter balanced. I remove err_clock label at the same. > > Fixes: 6cd225cc5d8a ("hwrng: exynos - add Samsung Exynos True RNG driver") > Reported-by: Hulk Robot <hulkci@huawei.com> > Suggested-by: Lukasz Stelmach <l.stelmach@samsung.com> > Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com> > --- > v2: remobe useless label as Lukasz suggested. That is good too, but I meant using pm_runtime_resume_and_get() in exynos_trng_resume() too. Please take a look at that function. > > drivers/char/hw_random/exynos-trng.c | 9 +++------ > 1 file changed, 3 insertions(+), 6 deletions(-) > > diff --git a/drivers/char/hw_random/exynos-trng.c b/drivers/char/hw_random/exynos-trng.c > index 8e1fe3f8d..ffebb72e4 100644 > --- a/drivers/char/hw_random/exynos-trng.c > +++ b/drivers/char/hw_random/exynos-trng.c > @@ -132,7 +132,7 @@ static int exynos_trng_probe(struct platform_device *pdev) > return PTR_ERR(trng->mem); > > pm_runtime_enable(&pdev->dev); > - ret = pm_runtime_get_sync(&pdev->dev); > + ret = pm_runtime_resume_and_get(&pdev->dev); > if (ret < 0) { > dev_err(&pdev->dev, "Could not get runtime PM.\n"); > goto err_pm_get; > @@ -142,13 +142,13 @@ static int exynos_trng_probe(struct platform_device *pdev) > if (IS_ERR(trng->clk)) { > ret = PTR_ERR(trng->clk); > dev_err(&pdev->dev, "Could not get clock.\n"); > - goto err_clock; > + goto err_pm_get; > } > > ret = clk_prepare_enable(trng->clk); > if (ret) { > dev_err(&pdev->dev, "Could not enable the clk.\n"); > - goto err_clock; > + goto err_pm_get; > } > > ret = devm_hwrng_register(&pdev->dev, &trng->rng); > @@ -164,9 +164,6 @@ static int exynos_trng_probe(struct platform_device *pdev) > err_register: > clk_disable_unprepare(trng->clk); > > -err_clock: > - pm_runtime_put_sync(&pdev->dev); > - > err_pm_get: > pm_runtime_disable(&pdev->dev);
diff --git a/drivers/char/hw_random/exynos-trng.c b/drivers/char/hw_random/exynos-trng.c index 8e1fe3f8d..ffebb72e4 100644 --- a/drivers/char/hw_random/exynos-trng.c +++ b/drivers/char/hw_random/exynos-trng.c @@ -132,7 +132,7 @@ static int exynos_trng_probe(struct platform_device *pdev) return PTR_ERR(trng->mem); pm_runtime_enable(&pdev->dev); - ret = pm_runtime_get_sync(&pdev->dev); + ret = pm_runtime_resume_and_get(&pdev->dev); if (ret < 0) { dev_err(&pdev->dev, "Could not get runtime PM.\n"); goto err_pm_get; @@ -142,13 +142,13 @@ static int exynos_trng_probe(struct platform_device *pdev) if (IS_ERR(trng->clk)) { ret = PTR_ERR(trng->clk); dev_err(&pdev->dev, "Could not get clock.\n"); - goto err_clock; + goto err_pm_get; } ret = clk_prepare_enable(trng->clk); if (ret) { dev_err(&pdev->dev, "Could not enable the clk.\n"); - goto err_clock; + goto err_pm_get; } ret = devm_hwrng_register(&pdev->dev, &trng->rng); @@ -164,9 +164,6 @@ static int exynos_trng_probe(struct platform_device *pdev) err_register: clk_disable_unprepare(trng->clk); -err_clock: - pm_runtime_put_sync(&pdev->dev); - err_pm_get: pm_runtime_disable(&pdev->dev);
pm_runtime_get_sync will increment pm usage counter even failed. Forgetting to putting operation will result in a reference leak here. Replace it with pm_runtime_resume_and_get to keep usage counter balanced. I remove err_clock label at the same. Fixes: 6cd225cc5d8a ("hwrng: exynos - add Samsung Exynos True RNG driver") Reported-by: Hulk Robot <hulkci@huawei.com> Suggested-by: Lukasz Stelmach <l.stelmach@samsung.com> Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com> --- v2: remobe useless label as Lukasz suggested. drivers/char/hw_random/exynos-trng.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)