Skip to contentSkip to conversation

drm/gma500: Remove VLA

PATCH Applied Laura Abbott 3 participants 3 messages Apr 9, 2018 – May 23, 2018

Subsystems (3)

v1 of 3 Applied Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/gma500: Remove VLA

There's an ongoing effort to remove VLAs[1] from the kernel to eventually turn on -Wvla. Switch to a reasonable upper bound for the VLAs in the gma500 driver.

[1] https://lkml.org/lkml/2018/3/7/621

---
This was a little hard to figure out but I think 32 should be a comfortable upper bound based on all the structures I saw. Of course I can't test it.

---
 drivers/gpu/drm/gma500/psb_intel_sdvo.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/gma500/psb_intel_sdvo.c +9 -2
index 84507912be84..3d4fa9f6b94c 100644
@@ -429,13 +429,20 @@ static const char *cmd_status_names[] = {
 	"Scaling not supported"
 };
 
+#define MAX_ARG_LEN 32
+
 static bool psb_intel_sdvo_write_cmd(struct psb_intel_sdvo *psb_intel_sdvo, u8 cmd,
 				 const void *args, int args_len)
 {
-	u8 buf[args_len*2 + 2], status;
-	struct i2c_msg msgs[args_len + 3];
+	u8 buf[MAX_ARG_LEN*2 + 2], status;
+	struct i2c_msg msgs[MAX_ARG_LEN + 3];
 	int i, ret;
 
+	if (args_len > MAX_ARG_LEN) {
+		DRM_ERROR("Need to increase arg length\n");
+		return false;
+	}
+
 	psb_intel_sdvo_debug_write(psb_intel_sdvo, cmd, args, args_len);
 
 	for (i = 0; i < args_len; i++) {
Signature · 1 line
2.14.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Laura Abbott

There's an ongoing effort to remove VLAs[1] from the kernel to eventually turn on -Wvla. Switch to a reasonable upper bound for the VLAs in the gma500 driver.

[1] https://lkml.org/lkml/2018/3/7/621

Daniel, can this go via you, or what's the best path for this patch?

Thanks!

-Kees

Quoted 38 lines

---
This was a little hard to figure out but I think 32 should be a comfortable upper bound based on all the structures I saw. Of course I can't test it.

---
 drivers/gpu/drm/gma500/psb_intel_sdvo.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/gma500/psb_intel_sdvo.c +9 -3
index 84507912be84..3d4fa9f6b94c 100644
@@ -429,13 +429,20 @@ static const char *cmd_status_names[] = {
        "Scaling not supported"
 };
 
+#define MAX_ARG_LEN 32
+
 static bool psb_intel_sdvo_write_cmd(struct psb_intel_sdvo *psb_intel_sdvo, u8 cmd,
                                 const void *args, int args_len)
 {
-       u8 buf[args_len*2 + 2], status;
-       struct i2c_msg msgs[args_len + 3];
+       u8 buf[MAX_ARG_LEN*2 + 2], status;
+       struct i2c_msg msgs[MAX_ARG_LEN + 3];
        int i, ret;
 
+       if (args_len > MAX_ARG_LEN) {
+               DRM_ERROR("Need to increase arg length\n");
+               return false;
+       }
+
        psb_intel_sdvo_debug_write(psb_intel_sdvo, cmd, args, args_len);
 
        for (i = 0; i < args_len; i++) {
--

2.14.3

Signature · 2 lines
Kees Cook
Pixel Security
#2 lore raw
Quoted 6 lines · Kees Cook
Quoted 5 lines · Laura Abbott

There's an ongoing effort to remove VLAs[1] from the kernel to eventually turn on -Wvla. Switch to a reasonable upper bound for the VLAs in the gma500 driver.

Quoted 7 lines
Quoted 3 lines

[1] https://lkml.org/lkml/2018/3/7/621

Daniel, can this go via you, or what's the best path for this patch?

Applied to drm-misc-next for 4.19, thanks.
-Daniel

Quoted 49 lines

Thanks!

-Kees

Quoted 38 lines

---
This was a little hard to figure out but I think 32 should be a comfortable upper bound based on all the structures I saw. Of course I can't test it.

---
 drivers/gpu/drm/gma500/psb_intel_sdvo.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/gma500/psb_intel_sdvo.c +9 -3
index 84507912be84..3d4fa9f6b94c 100644
@@ -429,13 +429,20 @@ static const char *cmd_status_names[] = {
        "Scaling not supported"
 };
 
+#define MAX_ARG_LEN 32
+
 static bool psb_intel_sdvo_write_cmd(struct psb_intel_sdvo *psb_intel_sdvo, u8 cmd,
                                 const void *args, int args_len)
 {
-       u8 buf[args_len*2 + 2], status;
-       struct i2c_msg msgs[args_len + 3];
+       u8 buf[MAX_ARG_LEN*2 + 2], status;
+       struct i2c_msg msgs[MAX_ARG_LEN + 3];
        int i, ret;
 
+       if (args_len > MAX_ARG_LEN) {
+               DRM_ERROR("Need to increase arg length\n");
+               return false;
+       }
+
        psb_intel_sdvo_debug_write(psb_intel_sdvo, cmd, args, args_len);
 
        for (i = 0; i < args_len; i++) {
--

2.14.3

Signature · 2 lines
Kees Cook
Pixel Security
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch