2020-06-13 21:44:40

by Qiushi Wu

[permalink] [raw]
Subject: [PATCH] char: hw_random: Fix a reference count leak.

From: Qiushi Wu <[email protected]>

Calling pm_runtime_get_sync increments the counter even in case of
failure, causing incorrect ref count if pm_runtime_put_sync is not
called in error handling paths. Thus replace the jump target
"err_pm_get" by "err_clock".

Fixes: 6cd225cc5d8a ("hwrng: exynos - add Samsung Exynos True RNG driver")
Signed-off-by: Qiushi Wu <[email protected]>
---
drivers/char/hw_random/exynos-trng.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/char/hw_random/exynos-trng.c b/drivers/char/hw_random/exynos-trng.c
index 8e1fe3f8dd2d..ffa7e0f061f0 100644
--- a/drivers/char/hw_random/exynos-trng.c
+++ b/drivers/char/hw_random/exynos-trng.c
@@ -135,7 +135,7 @@ static int exynos_trng_probe(struct platform_device *pdev)
ret = pm_runtime_get_sync(&pdev->dev);
if (ret < 0) {
dev_err(&pdev->dev, "Could not get runtime PM.\n");
- goto err_pm_get;
+ goto err_clock;
}

trng->clk = devm_clk_get(&pdev->dev, "secss");
@@ -166,8 +166,6 @@ static int exynos_trng_probe(struct platform_device *pdev)

err_clock:
pm_runtime_put_sync(&pdev->dev);
-
-err_pm_get:
pm_runtime_disable(&pdev->dev);

return ret;
--
2.17.1


2020-06-15 13:23:04

by Łukasz Stelmach

[permalink] [raw]
Subject: Re: [PATCH] char: hw_random: Fix a reference count leak.

It was <2020-06-13 sob 16:41>, when [email protected] wrote:
> From: Qiushi Wu <[email protected]>
>
> Calling pm_runtime_get_sync increments the counter even in case of
> failure, causing incorrect ref count if pm_runtime_put_sync is not
> called in error handling paths. Thus replace the jump target
> "err_pm_get" by "err_clock".
>
> Fixes: 6cd225cc5d8a ("hwrng: exynos - add Samsung Exynos True RNG driver")
> Signed-off-by: Qiushi Wu <[email protected]>
> ---
> drivers/char/hw_random/exynos-trng.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/char/hw_random/exynos-trng.c b/drivers/char/hw_random/exynos-trng.c
> index 8e1fe3f8dd2d..ffa7e0f061f0 100644
> --- a/drivers/char/hw_random/exynos-trng.c
> +++ b/drivers/char/hw_random/exynos-trng.c
> @@ -135,7 +135,7 @@ static int exynos_trng_probe(struct platform_device *pdev)
> ret = pm_runtime_get_sync(&pdev->dev);
> if (ret < 0) {
> dev_err(&pdev->dev, "Could not get runtime PM.\n");
> - goto err_pm_get;
> + goto err_clock;
> }
>
> trng->clk = devm_clk_get(&pdev->dev, "secss");
> @@ -166,8 +166,6 @@ static int exynos_trng_probe(struct platform_device *pdev)
>
> err_clock:
> pm_runtime_put_sync(&pdev->dev);
> -
> -err_pm_get:
> pm_runtime_disable(&pdev->dev);
>
> return ret;

I believe this fix has already been submitted

https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#u

It hasn't been applied though. Anyway, thank you for your work.

Herbert, could you take a look at the Dinghao's patch, please?
--
Łukasz Stelmach
Samsung R&D Institute Poland
Samsung Electronics


Attachments:
signature.asc (497.00 B)