diff mbox series

hwrng: ingenic - Fix a resource leak in an error handling path

Message ID 20201219075207.176279-1-christophe.jaillet@wanadoo.fr (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series hwrng: ingenic - Fix a resource leak in an error handling path | expand

Commit Message

Christophe JAILLET Dec. 19, 2020, 7:52 a.m. UTC
In case of error, we should call 'clk_disable_unprepare()' to undo a
previous 'clk_prepare_enable()' call, as already done in the remove
function.

Fixes: 406346d22278 ("hwrng: ingenic - Add hardware TRNG for Ingenic X1830")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/char/hw_random/ingenic-trng.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Zhou Yanjie Dec. 20, 2020, 1:30 p.m. UTC | #1
Hi Christophe,

On 2020/12/19 下午3:52, Christophe JAILLET wrote:
> In case of error, we should call 'clk_disable_unprepare()' to undo a
> previous 'clk_prepare_enable()' call, as already done in the remove
> function.
>
> Fixes: 406346d22278 ("hwrng: ingenic - Add hardware TRNG for Ingenic X1830")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>   drivers/char/hw_random/ingenic-trng.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)


Thanks for fixing it, and apologize for my carelessness.

Tested-by: 周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>


> diff --git a/drivers/char/hw_random/ingenic-trng.c b/drivers/char/hw_random/ingenic-trng.c
> index 954a8411d67d..0eb80f786f4d 100644
> --- a/drivers/char/hw_random/ingenic-trng.c
> +++ b/drivers/char/hw_random/ingenic-trng.c
> @@ -113,13 +113,17 @@ static int ingenic_trng_probe(struct platform_device *pdev)
>   	ret = hwrng_register(&trng->rng);
>   	if (ret) {
>   		dev_err(&pdev->dev, "Failed to register hwrng\n");
> -		return ret;
> +		goto err_unprepare_clk;
>   	}
>   
>   	platform_set_drvdata(pdev, trng);
>   
>   	dev_info(&pdev->dev, "Ingenic DTRNG driver registered\n");
>   	return 0;
> +
> +err_unprepare_clk:
> +	clk_disable_unprepare(trng->clk);
> +	return ret;
>   }
>   
>   static int ingenic_trng_remove(struct platform_device *pdev)
Herbert Xu Jan. 2, 2021, 10:08 p.m. UTC | #2
On Sat, Dec 19, 2020 at 08:52:07AM +0100, Christophe JAILLET wrote:
> In case of error, we should call 'clk_disable_unprepare()' to undo a
> previous 'clk_prepare_enable()' call, as already done in the remove
> function.
> 
> Fixes: 406346d22278 ("hwrng: ingenic - Add hardware TRNG for Ingenic X1830")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/char/hw_random/ingenic-trng.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

Patch applied.  Thanks.
diff mbox series

Patch

diff --git a/drivers/char/hw_random/ingenic-trng.c b/drivers/char/hw_random/ingenic-trng.c
index 954a8411d67d..0eb80f786f4d 100644
--- a/drivers/char/hw_random/ingenic-trng.c
+++ b/drivers/char/hw_random/ingenic-trng.c
@@ -113,13 +113,17 @@  static int ingenic_trng_probe(struct platform_device *pdev)
 	ret = hwrng_register(&trng->rng);
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to register hwrng\n");
-		return ret;
+		goto err_unprepare_clk;
 	}
 
 	platform_set_drvdata(pdev, trng);
 
 	dev_info(&pdev->dev, "Ingenic DTRNG driver registered\n");
 	return 0;
+
+err_unprepare_clk:
+	clk_disable_unprepare(trng->clk);
+	return ret;
 }
 
 static int ingenic_trng_remove(struct platform_device *pdev)