All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto: stm32 - Handle failure of kmalloc_array()
@ 2022-06-22  2:02 ` Li Qiong
  0 siblings, 0 replies; 4+ messages in thread
From: Li Qiong @ 2022-06-22  2:02 UTC (permalink / raw)
  To: Herbert Xu, David S . Miller, Maxime Coquelin, Alexandre Torgue,
	Rafael J . Wysocki
  Cc: linux-crypto, linux-stm32, linux-arm-kernel, linux-kernel, yuzhe,
	renyu, Li Qiong

As the possible failure of the kmalloc_array(), therefore it
should be better to check it and return '-ENOMEM' on error.

Signed-off-by: Li Qiong <liqiong@nfschina.com>
---
 drivers/crypto/stm32/stm32-hash.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32-hash.c
index d33006d43f76..fc03e32e364f 100644
--- a/drivers/crypto/stm32/stm32-hash.c
+++ b/drivers/crypto/stm32/stm32-hash.c
@@ -970,6 +970,8 @@ static int stm32_hash_export(struct ahash_request *req, void *out)
 	rctx->hw_context = kmalloc_array(3 + HASH_CSR_REGISTER_NUMBER,
 					 sizeof(u32),
 					 GFP_KERNEL);
+	if (!rctx->hw_context)
+		return -ENOMEM;
 
 	preg = rctx->hw_context;
 
-- 
2.11.0


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

* [PATCH] crypto: stm32 - Handle failure of kmalloc_array()
@ 2022-06-22  2:02 ` Li Qiong
  0 siblings, 0 replies; 4+ messages in thread
From: Li Qiong @ 2022-06-22  2:02 UTC (permalink / raw)
  To: Herbert Xu, David S . Miller, Maxime Coquelin, Alexandre Torgue,
	Rafael J . Wysocki
  Cc: linux-crypto, linux-stm32, linux-arm-kernel, linux-kernel, yuzhe,
	renyu, Li Qiong

As the possible failure of the kmalloc_array(), therefore it
should be better to check it and return '-ENOMEM' on error.

Signed-off-by: Li Qiong <liqiong@nfschina.com>
---
 drivers/crypto/stm32/stm32-hash.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32-hash.c
index d33006d43f76..fc03e32e364f 100644
--- a/drivers/crypto/stm32/stm32-hash.c
+++ b/drivers/crypto/stm32/stm32-hash.c
@@ -970,6 +970,8 @@ static int stm32_hash_export(struct ahash_request *req, void *out)
 	rctx->hw_context = kmalloc_array(3 + HASH_CSR_REGISTER_NUMBER,
 					 sizeof(u32),
 					 GFP_KERNEL);
+	if (!rctx->hw_context)
+		return -ENOMEM;
 
 	preg = rctx->hw_context;
 
-- 
2.11.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] crypto: stm32 - Handle failure of kmalloc_array()
  2022-06-22  2:02 ` Li Qiong
@ 2022-06-30  6:48   ` Herbert Xu
  -1 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2022-06-30  6:48 UTC (permalink / raw)
  To: Li Qiong
  Cc: David S . Miller, Maxime Coquelin, Alexandre Torgue,
	Rafael J . Wysocki, linux-crypto, linux-stm32, linux-arm-kernel,
	linux-kernel, yuzhe, renyu

On Wed, Jun 22, 2022 at 10:02:08AM +0800, Li Qiong wrote:
> As the possible failure of the kmalloc_array(), therefore it
> should be better to check it and return '-ENOMEM' on error.
> 
> Signed-off-by: Li Qiong <liqiong@nfschina.com>
> ---
>  drivers/crypto/stm32/stm32-hash.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32-hash.c
> index d33006d43f76..fc03e32e364f 100644
> --- a/drivers/crypto/stm32/stm32-hash.c
> +++ b/drivers/crypto/stm32/stm32-hash.c
> @@ -970,6 +970,8 @@ static int stm32_hash_export(struct ahash_request *req, void *out)
>  	rctx->hw_context = kmalloc_array(3 + HASH_CSR_REGISTER_NUMBER,
>  					 sizeof(u32),
>  					 GFP_KERNEL);
> +	if (!rctx->hw_context)
> +		return -ENOMEM;

Actually the problem is bigger than that.  The driver should not be
allocating memory in the export function at all.  This memory will
be leaked as exported requests won't be finalized.

We need to fix this driver to do export properly, or if that's not
possible, we should delete this driver.

Cheers,
-- 
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] 4+ messages in thread

* Re: [PATCH] crypto: stm32 - Handle failure of kmalloc_array()
@ 2022-06-30  6:48   ` Herbert Xu
  0 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2022-06-30  6:48 UTC (permalink / raw)
  To: Li Qiong
  Cc: David S . Miller, Maxime Coquelin, Alexandre Torgue,
	Rafael J . Wysocki, linux-crypto, linux-stm32, linux-arm-kernel,
	linux-kernel, yuzhe, renyu

On Wed, Jun 22, 2022 at 10:02:08AM +0800, Li Qiong wrote:
> As the possible failure of the kmalloc_array(), therefore it
> should be better to check it and return '-ENOMEM' on error.
> 
> Signed-off-by: Li Qiong <liqiong@nfschina.com>
> ---
>  drivers/crypto/stm32/stm32-hash.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32-hash.c
> index d33006d43f76..fc03e32e364f 100644
> --- a/drivers/crypto/stm32/stm32-hash.c
> +++ b/drivers/crypto/stm32/stm32-hash.c
> @@ -970,6 +970,8 @@ static int stm32_hash_export(struct ahash_request *req, void *out)
>  	rctx->hw_context = kmalloc_array(3 + HASH_CSR_REGISTER_NUMBER,
>  					 sizeof(u32),
>  					 GFP_KERNEL);
> +	if (!rctx->hw_context)
> +		return -ENOMEM;

Actually the problem is bigger than that.  The driver should not be
allocating memory in the export function at all.  This memory will
be leaked as exported requests won't be finalized.

We need to fix this driver to do export properly, or if that's not
possible, we should delete this driver.

Cheers,
-- 
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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-06-30  6:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-22  2:02 [PATCH] crypto: stm32 - Handle failure of kmalloc_array() Li Qiong
2022-06-22  2:02 ` Li Qiong
2022-06-30  6:48 ` Herbert Xu
2022-06-30  6:48   ` Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.