diff mbox series

crypto: ingenic - Drop kfree for memory allocated with devm_kzalloc

Message ID 20200804081153.45342-1-weiyongjun1@huawei.com (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series crypto: ingenic - Drop kfree for memory allocated with devm_kzalloc | expand

Commit Message

Wei Yongjun Aug. 4, 2020, 8:11 a.m. UTC
It's not necessary to free memory allocated with devm_kzalloc
and using kfree leads to a double free.

Fixes: 190873a0ea45 ("crypto: ingenic - Add hardware RNG for Ingenic JZ4780 and X1000")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 drivers/char/hw_random/ingenic-rng.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

Comments

Zhou Yanjie Aug. 7, 2020, 3:57 p.m. UTC | #1
Hello,

在 2020/8/4 下午4:11, Wei Yongjun 写道:
> It's not necessary to free memory allocated with devm_kzalloc
> and using kfree leads to a double free.


Thanks for fix it.

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

>
> Fixes: 190873a0ea45 ("crypto: ingenic - Add hardware RNG for Ingenic JZ4780 and X1000")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---
>   drivers/char/hw_random/ingenic-rng.c | 9 ++-------
>   1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/char/hw_random/ingenic-rng.c b/drivers/char/hw_random/ingenic-rng.c
> index d704cef64b64..055cfe59f519 100644
> --- a/drivers/char/hw_random/ingenic-rng.c
> +++ b/drivers/char/hw_random/ingenic-rng.c
> @@ -92,8 +92,7 @@ static int ingenic_rng_probe(struct platform_device *pdev)
>   	priv->base = devm_platform_ioremap_resource(pdev, 0);
>   	if (IS_ERR(priv->base)) {
>   		pr_err("%s: Failed to map RNG registers\n", __func__);
> -		ret = PTR_ERR(priv->base);
> -		goto err_free_rng;
> +		return PTR_ERR(priv->base);
>   	}
>   
>   	priv->version = (enum ingenic_rng_version)of_device_get_match_data(&pdev->dev);
> @@ -106,17 +105,13 @@ static int ingenic_rng_probe(struct platform_device *pdev)
>   	ret = hwrng_register(&priv->rng);
>   	if (ret) {
>   		dev_err(&pdev->dev, "Failed to register hwrng\n");
> -		goto err_free_rng;
> +		return ret;
>   	}
>   
>   	platform_set_drvdata(pdev, priv);
>   
>   	dev_info(&pdev->dev, "Ingenic RNG driver registered\n");
>   	return 0;
> -
> -err_free_rng:
> -	kfree(priv);
> -	return ret;
>   }
>   
>   static int ingenic_rng_remove(struct platform_device *pdev)
>
>
Herbert Xu Aug. 21, 2020, 7:56 a.m. UTC | #2
On Tue, Aug 04, 2020 at 08:11:53AM +0000, Wei Yongjun wrote:
> It's not necessary to free memory allocated with devm_kzalloc
> and using kfree leads to a double free.
> 
> Fixes: 190873a0ea45 ("crypto: ingenic - Add hardware RNG for Ingenic JZ4780 and X1000")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> ---
>  drivers/char/hw_random/ingenic-rng.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)

Patch applied.  Thanks.
diff mbox series

Patch

diff --git a/drivers/char/hw_random/ingenic-rng.c b/drivers/char/hw_random/ingenic-rng.c
index d704cef64b64..055cfe59f519 100644
--- a/drivers/char/hw_random/ingenic-rng.c
+++ b/drivers/char/hw_random/ingenic-rng.c
@@ -92,8 +92,7 @@  static int ingenic_rng_probe(struct platform_device *pdev)
 	priv->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(priv->base)) {
 		pr_err("%s: Failed to map RNG registers\n", __func__);
-		ret = PTR_ERR(priv->base);
-		goto err_free_rng;
+		return PTR_ERR(priv->base);
 	}
 
 	priv->version = (enum ingenic_rng_version)of_device_get_match_data(&pdev->dev);
@@ -106,17 +105,13 @@  static int ingenic_rng_probe(struct platform_device *pdev)
 	ret = hwrng_register(&priv->rng);
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to register hwrng\n");
-		goto err_free_rng;
+		return ret;
 	}
 
 	platform_set_drvdata(pdev, priv);
 
 	dev_info(&pdev->dev, "Ingenic RNG driver registered\n");
 	return 0;
-
-err_free_rng:
-	kfree(priv);
-	return ret;
 }
 
 static int ingenic_rng_remove(struct platform_device *pdev)