Skip to content

Commit ba26cd7

Browse files
author
Boris Brezillon
committed
mtd: sa1100: avoid VLA in sa1100_setup_mtd
Enabling -Wvla found another variable-length array with randconfig testing: drivers/mtd/maps/sa1100-flash.c: In function 'sa1100_setup_mtd': drivers/mtd/maps/sa1100-flash.c:224:10: error: ISO C90 forbids variable length array 'cdev' [-Werror=vla] Dynamically allocate the cdev array passed to mtd_concat_create() instead of using a VLA. Reported-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com> Cc: Kees Cook <keescook@chromium.org> Cc: Olof Johansson <olof@lixom.net>
1 parent 90c31cb commit ba26cd7

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎drivers/mtd/maps/sa1100-flash.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,14 @@ static struct sa_info *sa1100_setup_mtd(struct platform_device *pdev,
221221
info->mtd = info->subdev[0].mtd;
222222
ret = 0;
223223
} else if (info->num_subdev > 1) {
224-
struct mtd_info *cdev[nr];
224+
struct mtd_info **cdev;
225+
226+
cdev = kmalloc_array(nr, sizeof(*cdev), GFP_KERNEL);
227+
if (!cdev) {
228+
ret = -ENOMEM;
229+
goto err;
230+
}
231+
225232
/*
226233
* We detected multiple devices. Concatenate them together.
227234
*/
@@ -230,6 +237,7 @@ static struct sa_info *sa1100_setup_mtd(struct platform_device *pdev,
230237

231238
info->mtd = mtd_concat_create(cdev, info->num_subdev,
232239
plat->name);
240+
kfree(cdev);
233241
if (info->mtd == NULL) {
234242
ret = -ENXIO;
235243
goto err;

0 commit comments

Comments
 (0)