Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: concat: Use kmemdup_array instead of kmemdup for multiple allocation

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>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20240823110824.3895787-1-yanzhen@vivo.com

authored by

Yan Zhen and committed by
Miquel Raynal
175086cf e334c01d

+1 -1
+1 -1
drivers/mtd/mtdconcat.c
··· 204 204 } 205 205 206 206 /* make a copy of vecs */ 207 - vecs_copy = kmemdup(vecs, sizeof(struct kvec) * count, GFP_KERNEL); 207 + vecs_copy = kmemdup_array(vecs, count, sizeof(struct kvec), GFP_KERNEL); 208 208 if (!vecs_copy) 209 209 return -ENOMEM; 210 210