linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: ingenic - Drop kfree for memory allocated with devm_kzalloc
@ 2020-08-04  8:11 Wei Yongjun
  2020-08-07 15:57 ` Zhou Yanjie
  2020-08-21  7:56 ` Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Wei Yongjun @ 2020-08-04  8:11 UTC (permalink / raw)
  To: mpm, herbert, arnd, gregkh, zhouyanjie, prasannatsmkumar
  Cc: Wei Yongjun, linux-crypto, kernel-janitors, Hulk Robot

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(-)

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)




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] crypto: ingenic - Drop kfree for memory allocated with devm_kzalloc
  2020-08-04  8:11 [PATCH] crypto: ingenic - Drop kfree for memory allocated with devm_kzalloc Wei Yongjun
@ 2020-08-07 15:57 ` Zhou Yanjie
  2020-08-21  7:56 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Zhou Yanjie @ 2020-08-07 15:57 UTC (permalink / raw)
  To: Wei Yongjun, mpm, herbert, arnd, gregkh, prasannatsmkumar
  Cc: linux-crypto, kernel-janitors, Hulk Robot

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)
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] crypto: ingenic - Drop kfree for memory allocated with devm_kzalloc
  2020-08-04  8:11 [PATCH] crypto: ingenic - Drop kfree for memory allocated with devm_kzalloc Wei Yongjun
  2020-08-07 15:57 ` Zhou Yanjie
@ 2020-08-21  7:56 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2020-08-21  7:56 UTC (permalink / raw)
  To: Wei Yongjun
  Cc: mpm, arnd, gregkh, zhouyanjie, prasannatsmkumar, linux-crypto,
	kernel-janitors, Hulk Robot

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.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-21  7:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-04  8:11 [PATCH] crypto: ingenic - Drop kfree for memory allocated with devm_kzalloc Wei Yongjun
2020-08-07 15:57 ` Zhou Yanjie
2020-08-21  7:56 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).