mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/1] crypto: caam - use kmalloc_array() instead of kmalloc()
@ 2025-11-21  2:44 Gongwei Li
  2025-12-19  3:31 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Gongwei Li @ 2025-11-21  2:44 UTC (permalink / raw)
  To: horia.geanta, pankaj.gupta, gaurav.jain, herbert, davem
  Cc: linux-crypto, linux-kernel, Gongwei Li

From: Gongwei Li <ligongwei@kylinos.cn>

Replace kmalloc() with kmalloc_array() to prevent potential
overflow, as recommended in Documentation/process/deprecated.rst.

Signed-off-by: Gongwei Li <ligongwei@kylinos.cn>
---
 drivers/crypto/caam/ctrl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 320be5d77737..81583251b1f6 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -208,7 +208,7 @@ static int deinstantiate_rng(struct device *ctrldev, int state_handle_mask)
 	u32 *desc, status;
 	int sh_idx, ret = 0;
 
-	desc = kmalloc(CAAM_CMD_SZ * 3, GFP_KERNEL);
+	desc = kmalloc_array(3, CAAM_CMD_SZ, GFP_KERNEL);
 	if (!desc)
 		return -ENOMEM;
 
@@ -285,7 +285,7 @@ static int instantiate_rng(struct device *ctrldev, int state_handle_mask,
 	int ret = 0, sh_idx;
 
 	ctrl = (struct caam_ctrl __iomem *)ctrlpriv->ctrl;
-	desc = kmalloc(CAAM_CMD_SZ * 7, GFP_KERNEL);
+	desc = kmalloc_array(7, CAAM_CMD_SZ, GFP_KERNEL);
 	if (!desc)
 		return -ENOMEM;
 
-- 
2.25.1


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

* Re: [PATCH 1/1] crypto: caam - use kmalloc_array() instead of kmalloc()
  2025-11-21  2:44 [PATCH 1/1] crypto: caam - use kmalloc_array() instead of kmalloc() Gongwei Li
@ 2025-12-19  3:31 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2025-12-19  3:31 UTC (permalink / raw)
  To: Gongwei Li
  Cc: horia.geanta, pankaj.gupta, gaurav.jain, davem, linux-crypto,
	linux-kernel, Gongwei Li

On Fri, Nov 21, 2025 at 10:44:56AM +0800, Gongwei Li wrote:
> From: Gongwei Li <ligongwei@kylinos.cn>
> 
> Replace kmalloc() with kmalloc_array() to prevent potential
> overflow, as recommended in Documentation/process/deprecated.rst.
> 
> Signed-off-by: Gongwei Li <ligongwei@kylinos.cn>
> ---
>  drivers/crypto/caam/ctrl.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
> index 320be5d77737..81583251b1f6 100644
> --- a/drivers/crypto/caam/ctrl.c
> +++ b/drivers/crypto/caam/ctrl.c
> @@ -208,7 +208,7 @@ static int deinstantiate_rng(struct device *ctrldev, int state_handle_mask)
>  	u32 *desc, status;
>  	int sh_idx, ret = 0;
>  
> -	desc = kmalloc(CAAM_CMD_SZ * 3, GFP_KERNEL);
> +	desc = kmalloc_array(3, CAAM_CMD_SZ, GFP_KERNEL);

This is pointless because CAAM_CMD_SZ is a constant.

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] 2+ messages in thread

end of thread, other threads:[~2025-12-19  3:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-21  2:44 [PATCH 1/1] crypto: caam - use kmalloc_array() instead of kmalloc() Gongwei Li
2025-12-19  3:31 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®