Skip to contentSkip to conversation

video: fbdev: via_aux_vt1632: remove VLA usage

PATCH In review Gustavo A. R. Silva 3 participants 3 messages Mar 7, 2018 – Mar 8, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 video: fbdev: via_aux_vt1632: remove VLA usage

In preparation to enabling -Wvla, remove VLA and replace it with a fixed-length array instead. Also, remove variable 'len'.

Notice that no new IDs have been added in seven years.

---
 drivers/video/fbdev/via/via_aux_vt1632.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/video/fbdev/via/via_aux_vt1632.c +3 -3
index d24f4cd..0cd0d2a 100644
@@ -35,10 +35,10 @@ static void probe(struct via_aux_bus *bus, u8 addr)
 		.addr	=	addr,
 		.name	=	name};
 	/* check vendor id and device id */
-	const u8 id[] = {0x06, 0x11, 0x92, 0x31}, len = ARRAY_SIZE(id);
-	u8 tmp[len];
+	const u8 id[4] = {0x06, 0x11, 0x92, 0x31};
+	u8 tmp[4];
 
-	if (!via_aux_read(&drv, 0x00, tmp, len) || memcmp(id, tmp, len))
+	if (!via_aux_read(&drv, 0x00, tmp, 4) || memcmp(id, tmp, 4))
 		return;
 
 	printk(KERN_INFO "viafb: Found %s at address 0x%x\n", name, addr);
Signature · 1 line
2.7.4
#1 lore raw

Hi Gustavo,

Quoted 3 lines · Gustavo A. R. Silva

In preparation to enabling -Wvla, remove VLA and replace it with a fixed-length array instead. Also, remove variable 'len'.

What is the reason behind adding -Wvla? Is there a thread some that I can read up on?

Quoted 12 lines

Notice that no new IDs have been added in seven years.

---
 drivers/video/fbdev/via/via_aux_vt1632.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/video/fbdev/via/via_aux_vt1632.c +0 -0
index d24f4cd..0cd0d2a 100644

drivers/video/fbdev/via/via_aux_vt1632.c static void probe(struct via_aux_bus *bus, u8 addr) · line 41

Quoted 10 lines
drivers/video/fbdev/via/via_aux_vt1632.c +3 -3
@@ -35,10 +35,10 @@ static void probe(struct via_aux_bus *bus, u8 addr)
                .addr   =       addr,
                .name   =       name};
        /* check vendor id and device id */
-       const u8 id[] = {0x06, 0x11, 0x92, 0x31}, len = ARRAY_SIZE(id);
-       u8 tmp[len];
+       const u8 id[4] = {0x06, 0x11, 0x92, 0x31};
+       u8 tmp[4];
 
-       if (!via_aux_read(&drv, 0x00, tmp, len) || memcmp(id, tmp, len))
+       if (!via_aux_read(&drv, 0x00, tmp, 4) || memcmp(id, tmp, 4))

Generally, hard coding a bunch of numbers like that makes for confusing and fragile code.

A lot simpler and more obvious solution is like the following. It silences the compiler warning (-Wvla - pedantic) you while keeping the original clarity.

        const u8 id[] = {0x06, 0x11, 0x92, 0x31}, len = ARRAY_SIZE(id);

- u8 tmp[len];
+ u8 tmp[ARRAY_SIZE(id)]; // Using len causes a Wvla warning

HTH
Emil

#2 lore raw

Hi Emil,

Quoted 9 lines · Emil Velikov

Hi Gustavo,

Quoted 3 lines · Gustavo A. R. Silva

In preparation to enabling -Wvla, remove VLA and replace it with a fixed-length array instead. Also, remove variable 'len'.

What is the reason behind adding -Wvla? Is there a thread some that I can read up on?

Sure. This is the thread: https://lkml.org/lkml/2018/3/7/621

Quoted 20 lines
Quoted 20 lines

Notice that no new IDs have been added in seven years.

---
  drivers/video/fbdev/via/via_aux_vt1632.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/video/fbdev/via/via_aux_vt1632.c +2 -2
index d24f4cd..0cd0d2a 100644
@@ -35,10 +35,10 @@ static void probe(struct via_aux_bus *bus, u8 addr)
                 .addr   =       addr,
                 .name   =       name};
         /* check vendor id and device id */
-       const u8 id[] = {0x06, 0x11, 0x92, 0x31}, len = ARRAY_SIZE(id);
-       u8 tmp[len];
+       const u8 id[4] = {0x06, 0x11, 0x92, 0x31};
+       u8 tmp[4];
 
Quoted 6 lines

drivers/video/fbdev/via/via_aux_vt1632.c static void probe(struct via_aux_bus *bus, u8 addr) · line 41

Quoted 2 lines
drivers/video/fbdev/via/via_aux_vt1632.c +1 -1
-       if (!via_aux_read(&drv, 0x00, tmp, len) || memcmp(id, tmp, len))
+       if (!via_aux_read(&drv, 0x00, tmp, 4) || memcmp(id, tmp, 4))

Generally, hard coding a bunch of numbers like that makes for confusing and fragile code.

You are correct.

Review

Quoted 8 lines

A lot simpler and more obvious solution is like the following. It silences the compiler warning (-Wvla - pedantic) you while keeping the original clarity.

         const u8 id[] = {0x06, 0x11, 0x92, 0x31}, len = ARRAY_SIZE(id);
(quoted diff) +1 -1
-       u8 tmp[len];
+       u8 tmp[ARRAY_SIZE(id)]; // Using len causes a Wvla warning

Yeah, this works just fine.

There are a total of four instances of this same issue in other files for the VIA component. I'll fix them and send a single patch shortly.

Thanks for the feedback.
I appreciate it.
--
Gustavo