Skip to content

Commit

Permalink
mtd: sa1100: avoid VLA in sa1100_setup_mtd
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Boris Brezillon committed Nov 6, 2018
1 parent 90c31cb commit ba26cd7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion drivers/mtd/maps/sa1100-flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,14 @@ static struct sa_info *sa1100_setup_mtd(struct platform_device *pdev,
info->mtd = info->subdev[0].mtd;
ret = 0;
} else if (info->num_subdev > 1) {
struct mtd_info *cdev[nr];
struct mtd_info **cdev;

cdev = kmalloc_array(nr, sizeof(*cdev), GFP_KERNEL);
if (!cdev) {
ret = -ENOMEM;
goto err;
}

/*
* We detected multiple devices. Concatenate them together.
*/
Expand All @@ -230,6 +237,7 @@ static struct sa_info *sa1100_setup_mtd(struct platform_device *pdev,

info->mtd = mtd_concat_create(cdev, info->num_subdev,
plat->name);
kfree(cdev);
if (info->mtd == NULL) {
ret = -ENXIO;
goto err;
Expand Down

0 comments on commit ba26cd7

Please sign in to comment.