[PATCH] mtd: sa1100: avoid VLA in sa1100_setup_mtd
From: Arnd Bergmann
Date: Wed Oct 10 2018 - 14:46:16 EST
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]
As far as I can tell, there is an upper bound on the number of resources
that can be passed, based on the number of CS lines on the bus.
In practice, all boards we support have either one or two resources,
but using six to be on the safe side has no extra cost.
Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
---
drivers/mtd/maps/sa1100-flash.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
index 784c6e1a0391..234573b401bd 100644
--- a/drivers/mtd/maps/sa1100-flash.c
+++ b/drivers/mtd/maps/sa1100-flash.c
@@ -23,6 +23,8 @@
#include <asm/sizes.h>
#include <asm/mach/flash.h>
+#define SA1100_NUM_CS 6
+
struct sa_subdev_info {
char name[16];
struct map_info map;
@@ -157,7 +159,7 @@ static struct sa_info *sa1100_setup_mtd(struct platform_device *pdev,
/*
* Count number of devices.
*/
- for (nr = 0; ; nr++)
+ for (nr = 0; nr < SA1100_NUM_CS; nr++)
if (!platform_get_resource(pdev, IORESOURCE_MEM, nr))
break;
@@ -221,7 +223,7 @@ 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[SA1100_NUM_CS];
/*
* We detected multiple devices. Concatenate them together.
*/
--
2.18.0