Skip to contentSkip to conversation

crypto: caam - use kmalloc_array() instead of kmalloc()

PATCH In review Gongwei Li 2 participants 2 messages Nov 21, 2025 – Dec 19, 2025

Subsystems (2)
lore
Share & tools
lore

Gongwei Li

author
#0 lore raw

PATCH 1/1 crypto: caam - use kmalloc_array() instead of kmalloc()

From: Gongwei Li <[email protected]>

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

---
 drivers/crypto/caam/ctrl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/caam/ctrl.c +2 -2
index 320be5d77737..81583251b1f6 100644
@@ -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;
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 15 lines · Gongwei Li

From: Gongwei Li <[email protected]>

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

---
 drivers/crypto/caam/ctrl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/caam/ctrl.c +0 -0
index 320be5d77737..81583251b1f6 100644

drivers/crypto/caam/ctrl.c static int deinstantiate_rng(struct device *ctrldev, int state_handle_mask) · line 211

Quoted 5 lines
drivers/crypto/caam/ctrl.c +1 -1
@@ -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,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt