]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mtd: concat: Use kmemdup_array instead of kmemdup for multiple allocation
authorYan Zhen <yanzhen@vivo.com>
Fri, 23 Aug 2024 11:08:24 +0000 (19:08 +0800)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Fri, 23 Aug 2024 17:25:51 +0000 (19:25 +0200)
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
drivers/mtd/mtdconcat.c

index 193428de6a4bdfc324bd7c985ec7ebda28a658e6..f56f44aa8625ce27efe5f806a82ff89aec558e1a 100644 (file)
@@ -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;