diff mbox series

[v2] mtd: concat: Use kmemdup_array instead of kmemdup for multiple allocation

Message ID 20240823110824.3895787-1-yanzhen@vivo.com
State Accepted
Headers show
Series [v2] mtd: concat: Use kmemdup_array instead of kmemdup for multiple allocation | expand

Commit Message

Yan Zhen Aug. 23, 2024, 11:08 a.m. UTC
When we are allocating an array, using kmemdup_array() to take care about
multiplication and possible overflows.

Also it makes auditing the code easier.

Signed-off-by: Yan Zhen <yanzhen@vivo.com>
---

Changes in v2:
- Rewrite the patch title and the patch description

 drivers/mtd/mtdconcat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Miquel Raynal Aug. 23, 2024, 5:33 p.m. UTC | #1
On Fri, 2024-08-23 at 11:08:24 UTC, Yan Zhen wrote:
> When we are allocating an array, using kmemdup_array() to take care about
> multiplication and possible overflows.
> 
> Also it makes auditing the code easier.
> 
> Signed-off-by: Yan Zhen <yanzhen@vivo.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel
diff mbox series

Patch

diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index 193428de6a4b..f56f44aa8625 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -204,7 +204,7 @@  concat_writev(struct mtd_info *mtd, const struct kvec *vecs,
 	}
 
 	/* make a copy of vecs */
-	vecs_copy = kmemdup(vecs, sizeof(struct kvec) * count, GFP_KERNEL);
+	vecs_copy = kmemdup_array(vecs, count, sizeof(struct kvec), GFP_KERNEL);
 	if (!vecs_copy)
 		return -ENOMEM;