linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] video: fbdev: via_aux_vt1636: remove VLA usage
@ 2018-03-07 19:47 Gustavo A. R. Silva
  2018-03-09 10:11 ` Eric Engestrom
  0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2018-03-07 19:47 UTC (permalink / raw)
  To: Florian Tobias Schandinat, Bartlomiej Zolnierkiewicz
  Cc: linux-fbdev, dri-devel, linux-kernel, Gustavo A. R. Silva

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.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 drivers/video/fbdev/via/via_aux_vt1636.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/video/fbdev/via/via_aux_vt1636.c b/drivers/video/fbdev/via/via_aux_vt1636.c
index 9e015c1..d6273a4 100644
--- a/drivers/video/fbdev/via/via_aux_vt1636.c
+++ b/drivers/video/fbdev/via/via_aux_vt1636.c
@@ -35,10 +35,10 @@ void via_aux_vt1636_probe(struct via_aux_bus *bus)
 		.addr	=	0x40,
 		.name	=	name};
 	/* check vendor id and device id */
-	const u8 id[] = {0x06, 0x11, 0x45, 0x33}, len = ARRAY_SIZE(id);
-	u8 tmp[len];
+	const u8 id[4] = {0x06, 0x11, 0x45, 0x33};
+	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\n", name);
-- 
2.7.4

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

* Re: [PATCH] video: fbdev: via_aux_vt1636: remove VLA usage
  2018-03-07 19:47 [PATCH] video: fbdev: via_aux_vt1636: remove VLA usage Gustavo A. R. Silva
@ 2018-03-09 10:11 ` Eric Engestrom
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Engestrom @ 2018-03-09 10:11 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Florian Tobias Schandinat, Bartlomiej Zolnierkiewicz,
	linux-fbdev, Gustavo A. R. Silva, linux-kernel, dri-devel

On Wednesday, 2018-03-07 13:47:03 -0600, Gustavo A. R. Silva wrote:
> 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.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  drivers/video/fbdev/via/via_aux_vt1636.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/video/fbdev/via/via_aux_vt1636.c b/drivers/video/fbdev/via/via_aux_vt1636.c
> index 9e015c1..d6273a4 100644
> --- a/drivers/video/fbdev/via/via_aux_vt1636.c
> +++ b/drivers/video/fbdev/via/via_aux_vt1636.c
> @@ -35,10 +35,10 @@ void via_aux_vt1636_probe(struct via_aux_bus *bus)
>  		.addr	=	0x40,
>  		.name	=	name};
>  	/* check vendor id and device id */
> -	const u8 id[] = {0x06, 0x11, 0x45, 0x33}, len = ARRAY_SIZE(id);
> -	u8 tmp[len];
> +	const u8 id[4] = {0x06, 0x11, 0x45, 0x33};
> +	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))

I would recommend keeping ARRAY_SIZE(); even if nothing's been added in
a while, it's still clearer in the code if we can see where these `4`
come from.

Something like this instead?
----8<----
@@ -35,10 +35,10 @@ void via_aux_vt1636_probe(struct via_aux_bus *bus)
 		.addr	=	0x40,
 		.name	=	name};
 	/* check vendor id and device id */
-	const u8 id[] = {0x06, 0x11, 0x45, 0x33}, len = ARRAY_SIZE(id);
-	u8 tmp[len];
+	const u8 id[] = {0x06, 0x11, 0x45, 0x33};
+	u8 tmp[ARRAY_SIZE(id)];
 
-	if (!via_aux_read(&drv, 0x00, tmp, len) || memcmp(id, tmp, len))
+	if (!via_aux_read(&drv, 0x00, tmp, ARRAY_SIZE(id)) || memcmp(id, tmp, ARRAY_SIZE(id)))
 		return;
 
 	printk(KERN_INFO "viafb: Found %s\n", name);
---->8----

Note that sizeof is evaluated a compile time, so `u8 tmp[ARRAY_SIZE(id)]`
is *not* a VLA. All that's needed was to remove `len` :)

>  		return;
>  
>  	printk(KERN_INFO "viafb: Found %s\n", name);
> -- 
> 2.7.4
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

end of thread, other threads:[~2018-03-09 10:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-07 19:47 [PATCH] video: fbdev: via_aux_vt1636: remove VLA usage Gustavo A. R. Silva
2018-03-09 10:11 ` Eric Engestrom

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