linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: sa1100: avoid VLA in sa1100_setup_mtd
@ 2018-10-10 18:44 Arnd Bergmann
  2018-10-12  9:16 ` Boris Brezillon
  0 siblings, 1 reply; 7+ messages in thread
From: Arnd Bergmann @ 2018-10-10 18:44 UTC (permalink / raw)
  To: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
	Richard Weinberger
  Cc: Arnd Bergmann, linux-mtd, linux-kernel

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@arndb.de>
---
 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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] mtd: sa1100: avoid VLA in sa1100_setup_mtd
  2018-10-10 18:44 [PATCH] mtd: sa1100: avoid VLA in sa1100_setup_mtd Arnd Bergmann
@ 2018-10-12  9:16 ` Boris Brezillon
  2018-10-12  9:19   ` Arnd Bergmann
  0 siblings, 1 reply; 7+ messages in thread
From: Boris Brezillon @ 2018-10-12  9:16 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: David Woodhouse, Brian Norris, Marek Vasut, Richard Weinberger,
	linux-mtd, linux-kernel

Hi Arnd,

On Wed, 10 Oct 2018 20:44:50 +0200
Arnd Bergmann <arnd@arndb.de> wrote:

> 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.

Why not dynamically allocate cdev instead? That removes any kind of
guessing on the max value, and it shouldn't hurt much since this code is
in the probe path.

--->8---
diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
index 784c6e1a0391..fd5fe12d7461 100644
--- a/drivers/mtd/maps/sa1100-flash.c
+++ b/drivers/mtd/maps/sa1100-flash.c
@@ -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.
                 */
@@ -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;

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] mtd: sa1100: avoid VLA in sa1100_setup_mtd
  2018-10-12  9:16 ` Boris Brezillon
@ 2018-10-12  9:19   ` Arnd Bergmann
  2018-10-12  9:22     ` Boris Brezillon
  0 siblings, 1 reply; 7+ messages in thread
From: Arnd Bergmann @ 2018-10-12  9:19 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: David Woodhouse, Brian Norris, Marek Vasut, Richard Weinberger,
	linux-mtd, Linux Kernel Mailing List

On Fri, Oct 12, 2018 at 11:16 AM Boris Brezillon
<boris.brezillon@bootlin.com> wrote:
>
> Hi Arnd,
>
> On Wed, 10 Oct 2018 20:44:50 +0200
> Arnd Bergmann <arnd@arndb.de> wrote:
>
> > 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.
>
> Why not dynamically allocate cdev instead? That removes any kind of
> guessing on the max value, and it shouldn't hurt much since this code is
> in the probe path.

Fine with me as well, If you prefer that one, please just add
Reported-by: Arnd Bergmann <arnd@arndb.de>

       Arnd

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mtd: sa1100: avoid VLA in sa1100_setup_mtd
  2018-10-12  9:19   ` Arnd Bergmann
@ 2018-10-12  9:22     ` Boris Brezillon
  2018-10-29  2:13       ` Kees Cook
  0 siblings, 1 reply; 7+ messages in thread
From: Boris Brezillon @ 2018-10-12  9:22 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: David Woodhouse, Brian Norris, Marek Vasut, Richard Weinberger,
	linux-mtd, Linux Kernel Mailing List

On Fri, 12 Oct 2018 11:19:52 +0200
Arnd Bergmann <arnd@arndb.de> wrote:

> On Fri, Oct 12, 2018 at 11:16 AM Boris Brezillon
> <boris.brezillon@bootlin.com> wrote:
> >
> > Hi Arnd,
> >
> > On Wed, 10 Oct 2018 20:44:50 +0200
> > Arnd Bergmann <arnd@arndb.de> wrote:
> >  
> > > 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.  
> >
> > Why not dynamically allocate cdev instead? That removes any kind of
> > guessing on the max value, and it shouldn't hurt much since this code is
> > in the probe path.  
> 
> Fine with me as well, If you prefer that one, please just add
> Reported-by: Arnd Bergmann <arnd@arndb.de>

Oh, I thought I'd let you send a v2, but I can do it if you prefer.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mtd: sa1100: avoid VLA in sa1100_setup_mtd
  2018-10-12  9:22     ` Boris Brezillon
@ 2018-10-29  2:13       ` Kees Cook
  2018-10-29  7:30         ` Boris Brezillon
  0 siblings, 1 reply; 7+ messages in thread
From: Kees Cook @ 2018-10-29  2:13 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Arnd Bergmann, David Woodhouse, Brian Norris, Marek Vasut,
	Richard Weinberger, linux-mtd, Linux Kernel Mailing List,
	Olof Johansson

On Fri, Oct 12, 2018 at 2:22 AM, Boris Brezillon
<boris.brezillon@bootlin.com> wrote:
> On Fri, 12 Oct 2018 11:19:52 +0200
> Arnd Bergmann <arnd@arndb.de> wrote:
>
>> On Fri, Oct 12, 2018 at 11:16 AM Boris Brezillon
>> <boris.brezillon@bootlin.com> wrote:
>> >
>> > Hi Arnd,
>> >
>> > On Wed, 10 Oct 2018 20:44:50 +0200
>> > Arnd Bergmann <arnd@arndb.de> wrote:
>> >
>> > > 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.
>> >
>> > Why not dynamically allocate cdev instead? That removes any kind of
>> > guessing on the max value, and it shouldn't hurt much since this code is
>> > in the probe path.
>>
>> Fine with me as well, If you prefer that one, please just add
>> Reported-by: Arnd Bergmann <arnd@arndb.de>
>
> Oh, I thought I'd let you send a v2, but I can do it if you prefer.

Olof just pointed out to me that neither fix landed for this? What's
needed for this?

Thanks!

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mtd: sa1100: avoid VLA in sa1100_setup_mtd
  2018-10-29  2:13       ` Kees Cook
@ 2018-10-29  7:30         ` Boris Brezillon
  2018-10-29  9:46           ` Arnd Bergmann
  0 siblings, 1 reply; 7+ messages in thread
From: Boris Brezillon @ 2018-10-29  7:30 UTC (permalink / raw)
  To: Kees Cook
  Cc: Arnd Bergmann, David Woodhouse, Brian Norris, Marek Vasut,
	Richard Weinberger, linux-mtd, Linux Kernel Mailing List,
	Olof Johansson

Hi Kees,

On Sun, 28 Oct 2018 19:13:26 -0700
Kees Cook <keescook@chromium.org> wrote:

> On Fri, Oct 12, 2018 at 2:22 AM, Boris Brezillon
> <boris.brezillon@bootlin.com> wrote:
> > On Fri, 12 Oct 2018 11:19:52 +0200
> > Arnd Bergmann <arnd@arndb.de> wrote:
> >  
> >> On Fri, Oct 12, 2018 at 11:16 AM Boris Brezillon
> >> <boris.brezillon@bootlin.com> wrote:  
> >> >
> >> > Hi Arnd,
> >> >
> >> > On Wed, 10 Oct 2018 20:44:50 +0200
> >> > Arnd Bergmann <arnd@arndb.de> wrote:
> >> >  
> >> > > 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.  
> >> >
> >> > Why not dynamically allocate cdev instead? That removes any kind of
> >> > guessing on the max value, and it shouldn't hurt much since this code is
> >> > in the probe path.  
> >>
> >> Fine with me as well, If you prefer that one, please just add
> >> Reported-by: Arnd Bergmann <arnd@arndb.de>  
> >
> > Oh, I thought I'd let you send a v2, but I can do it if you prefer.  
> 
> Olof just pointed out to me that neither fix landed for this? What's
> needed for this?

Nothing in particular, I was planning on sending a new version after
-rc1 is out and then queue it for 4.21 (5.1?) (this patch came in a bit
late, and I had already stopped taking patches for 4.20).

If you consider this a fix or want to have it in 4.20 for other reasons,
just let me know and I'll queue it to the -fixes branch.

Regards,

Boris

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] mtd: sa1100: avoid VLA in sa1100_setup_mtd
  2018-10-29  7:30         ` Boris Brezillon
@ 2018-10-29  9:46           ` Arnd Bergmann
  0 siblings, 0 replies; 7+ messages in thread
From: Arnd Bergmann @ 2018-10-29  9:46 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Kees Cook, David Woodhouse, Brian Norris, Marek Vasut,
	Richard Weinberger, linux-mtd, Linux Kernel Mailing List,
	Olof Johansson

On Mon, Oct 29, 2018 at 8:30 AM Boris Brezillon
<boris.brezillon@bootlin.com> wrote:
> On Sun, 28 Oct 2018 19:13:26 -0700 Kees Cook <keescook@chromium.org> wrote:
> > On Fri, Oct 12, 2018 at 2:22 AM, Boris Brezillon <boris.brezillon@bootlin.com> wrote:
> > > On Fri, 12 Oct 2018 11:19:52 +0200 Arnd Bergmann <arnd@arndb.de> wrote:
> > > > On Fri, Oct 12, 2018 at 11:16 AM Boris Brezillon <boris.brezillon@bootlin.com> wrote:
> > > Oh, I thought I'd let you send a v2, but I can do it if you prefer.
> >
> > Olof just pointed out to me that neither fix landed for this? What's
> > needed for this?
>
> Nothing in particular, I was planning on sending a new version after
> -rc1 is out and then queue it for 4.21 (5.1?) (this patch came in a bit
> late, and I had already stopped taking patches for 4.20).
>
> If you consider this a fix or want to have it in 4.20 for other reasons,
> just let me know and I'll queue it to the -fixes branch.

We generally try to have a kernel that can be built in any configuration
without warnings, so please add it for v4.20.

        Arnd

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-10-29  9:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-10 18:44 [PATCH] mtd: sa1100: avoid VLA in sa1100_setup_mtd Arnd Bergmann
2018-10-12  9:16 ` Boris Brezillon
2018-10-12  9:19   ` Arnd Bergmann
2018-10-12  9:22     ` Boris Brezillon
2018-10-29  2:13       ` Kees Cook
2018-10-29  7:30         ` Boris Brezillon
2018-10-29  9:46           ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).