Skip to contentSkip to conversation

drm/edid: Distribute switch variables for initialization

PATCH In review Kees Cook 3 participants 4 messages Feb 20, 2020 – Mar 3, 2020

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 drm/edid: Distribute switch variables for initialization

Variables declared in a switch statement before any case statements cannot be automatically initialized with compiler instrumentation (as they are not part of any execution flow). With GCC's proposed automatic stack variable initialization feature, this triggers a warning (and they don't get initialized). Clang's automatic stack variable initialization (via CONFIG_INIT_STACK_ALL=y) doesn't throw a warning, but it also doesn't initialize such variables[1]. Note that these warnings (or silent skipping) happen before the dead-store elimination optimization phase, so even when the automatic initializations are later elided in favor of direct initializations, the warnings remain.

To avoid these problems, move such variables into the "case" where they're used or lift them up into the main function body.

drivers/gpu/drm/drm_edid.c: In function ‘drm_edid_to_eld’:
drivers/gpu/drm/drm_edid.c:4395:9: warning: statement will never be executed [-Wswitch-unreachable]

 4395 |     int sad_count;
      |         ^~~~~~~~~

[1] https://bugs.llvm.org/show_bug.cgi?id=44916

---
 drivers/gpu/drm/drm_edid.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_edid.c +3 -2
index 805fb004c8eb..2941b65b427f 100644
@@ -4392,9 +4392,9 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
 			dbl = cea_db_payload_len(db);
 
 			switch (cea_db_tag(db)) {
-				int sad_count;
+			case AUDIO_BLOCK: {
 
-			case AUDIO_BLOCK:
+				int sad_count;
 				/* Audio Data Block, contains SADs */
 				sad_count = min(dbl / 3, 15 - total_sad_count);
 				if (sad_count >= 1)
@@ -4402,6 +4402,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
 					       &db[1], sad_count * 3);
 				total_sad_count += sad_count;
 				break;
+			}
 			case SPEAKER_BLOCK:
 				/* Speaker Allocation Data Block */
 				if (dbl >= 1)
author
#1 lore raw
Quoted 14 lines · Kees Cook

Variables declared in a switch statement before any case statements cannot be automatically initialized with compiler instrumentation (as they are not part of any execution flow). With GCC's proposed automatic stack variable initialization feature, this triggers a warning (and they don't get initialized). Clang's automatic stack variable initialization (via CONFIG_INIT_STACK_ALL=y) doesn't throw a warning, but it also doesn't initialize such variables[1]. Note that these warnings (or silent skipping) happen before the dead-store elimination optimization phase, so even when the automatic initializations are later elided in favor of direct initializations, the warnings remain.

To avoid these problems, move such variables into the "case" where they're used or lift them up into the main function body.

Quoted 8 lines

drivers/gpu/drm/drm_edid.c: In function ‘drm_edid_to_eld’:
drivers/gpu/drm/drm_edid.c:4395:9: warning: statement will never be executed [-Wswitch-unreachable]

 4395 |     int sad_count;
      |         ^~~~~~~~~

[1] https://bugs.llvm.org/show_bug.cgi?id=44916

Ping. Can someone pick this up, please?

Thanks!

-Kees

Quoted 29 lines
---
 drivers/gpu/drm/drm_edid.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_edid.c +3 -2
index 805fb004c8eb..2941b65b427f 100644
@@ -4392,9 +4392,9 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
 			dbl = cea_db_payload_len(db);
 
 			switch (cea_db_tag(db)) {
-				int sad_count;
+			case AUDIO_BLOCK: {
 
-			case AUDIO_BLOCK:
+				int sad_count;
 				/* Audio Data Block, contains SADs */
 				sad_count = min(dbl / 3, 15 - total_sad_count);
 				if (sad_count >= 1)
@@ -4402,6 +4402,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
 					       &db[1], sad_count * 3);
 				total_sad_count += sad_count;
 				break;
+			}
 			case SPEAKER_BLOCK:
 				/* Speaker Allocation Data Block */
 				if (dbl >= 1)
Signature · 5 lines
Kees Cook
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw
Quoted 21 lines · Kees Cook
Quoted 19 lines · Kees Cook

Variables declared in a switch statement before any case statements cannot be automatically initialized with compiler instrumentation (as they are not part of any execution flow). With GCC's proposed automatic stack variable initialization feature, this triggers a warning (and they don't get initialized). Clang's automatic stack variable initialization (via CONFIG_INIT_STACK_ALL=y) doesn't throw a warning, but it also doesn't initialize such variables[1]. Note that these warnings (or silent skipping) happen before the dead-store elimination optimization phase, so even when the automatic initializations are later elided in favor of direct initializations, the warnings remain.

To avoid these problems, move such variables into the "case" where they're used or lift them up into the main function body.

drivers/gpu/drm/drm_edid.c: In function ‘drm_edid_to_eld’:
drivers/gpu/drm/drm_edid.c:4395:9: warning: statement will never be executed [-Wswitch-unreachable]

 4395 |     int sad_count;
      |         ^~~~~~~~~
Quoted 5 lines
Quoted 3 lines

[1] https://bugs.llvm.org/show_bug.cgi?id=44916

Ping. Can someone pick this up, please?

Whatever the reasons, but your original patch didn't make it through to dri-devel. Can you pls resubmit?

Thanks, Daniel

Quoted 37 lines

Thanks!

-Kees

Quoted 22 lines
---
 drivers/gpu/drm/drm_edid.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_edid.c +2 -2
index 805fb004c8eb..2941b65b427f 100644
@@ -4392,9 +4392,9 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
                      dbl = cea_db_payload_len(db);
 
                      switch (cea_db_tag(db)) {
-                             int sad_count;
+                     case AUDIO_BLOCK: {
 
-                     case AUDIO_BLOCK:
+                             int sad_count;
                              /* Audio Data Block, contains SADs */
                              sad_count = min(dbl / 3, 15 - total_sad_count);
                              if (sad_count >= 1)

drivers/gpu/drm/drm_edid.c static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) · line 4408

Quoted 7 lines
drivers/gpu/drm/drm_edid.c +1 -0
@@ -4402,6 +4402,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
                                             &db[1], sad_count * 3);
                              total_sad_count += sad_count;
                              break;
+                     }
                      case SPEAKER_BLOCK:
                              /* Speaker Allocation Data Block */
                              if (dbl >= 1)

--
Kees Cook

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw
In reply to Kees Cook
Quoted 41 lines · Kees Cook
Quoted 14 lines · Kees Cook

Variables declared in a switch statement before any case statements cannot be automatically initialized with compiler instrumentation (as they are not part of any execution flow). With GCC's proposed automatic stack variable initialization feature, this triggers a warning (and they don't get initialized). Clang's automatic stack variable initialization (via CONFIG_INIT_STACK_ALL=y) doesn't throw a warning, but it also doesn't initialize such variables[1]. Note that these warnings (or silent skipping) happen before the dead-store elimination optimization phase, so even when the automatic initializations are later elided in favor of direct initializations, the warnings remain.

To avoid these problems, move such variables into the "case" where they're used or lift them up into the main function body.

Quoted 8 lines

drivers/gpu/drm/drm_edid.c: In function ‘drm_edid_to_eld’:
drivers/gpu/drm/drm_edid.c:4395:9: warning: statement will never be executed [-Wswitch-unreachable]

 4395 |     int sad_count;
      |         ^~~~~~~~~

[1] https://bugs.llvm.org/show_bug.cgi?id=44916

Ping. Can someone pick this up, please?

Thanks!

-Kees

Quoted 11 lines
---
 drivers/gpu/drm/drm_edid.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_edid.c +0 -0
index 805fb004c8eb..2941b65b427f 100644
@@ -4392,9 +4392,9 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
 			dbl = cea_db_payload_len(db);
 
Quoted 3 lines

drivers/gpu/drm/drm_edid.c static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) · line 4395

Quoted 3 lines
drivers/gpu/drm/drm_edid.c +1 -1
 			switch (cea_db_tag(db)) {
-				int sad_count;
+			case AUDIO_BLOCK: {

I've never been a fan of {} inside switch statements. I'd just move this one level up.

Quoted 22 lines
Quoted 15 lines
drivers/gpu/drm/drm_edid.c +2 -1
-			case AUDIO_BLOCK:
+				int sad_count;
 				/* Audio Data Block, contains SADs */
 				sad_count = min(dbl / 3, 15 - total_sad_count);
 				if (sad_count >= 1)
@@ -4402,6 +4402,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
 					       &db[1], sad_count * 3);
 				total_sad_count += sad_count;
 				break;
+			}
 			case SPEAKER_BLOCK:
 				/* Speaker Allocation Data Block */
 				if (dbl >= 1)
Signature · 5 lines
Kees Cook
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 6 lines
Ville Syrjälä
Intel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel