Skip to contentSkip to conversation

drm/edid: Distribute switch variables for initialization

PATCH In review Kees Cook 3 participants 4 messages Mar 6, 2020 – Mar 16, 2020

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH v2 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, lift such variables up into the next code block.

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

---
v2: move into function block instead being switch-local (Ville Syrjälä)

---
 drivers/gpu/drm/drm_edid.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -2
index 805fb004c8eb..46cee78bc175 100644
@@ -4381,6 +4381,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
 
 	if (cea_revision(cea) >= 3) {
 		int i, start, end;
+		int sad_count;
 
 		if (cea_db_offsets(cea, &start, &end)) {
 			start = 0;
@@ -4392,8 +4393,6 @@ 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:
 				/* Audio Data Block, contains SADs */
 				sad_count = min(dbl / 3, 15 - total_sad_count);
Signature · 9 lines
2.20.1


-- 
Kees Cook
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 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

That's not good, have you filed a bug against Clang yet? It should at least warn when the corresponding stack init flag is set.

Quoted 10 lines

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, lift such variables up into the next code block.

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]

Quoted 6 lines
 4395 |     int sad_count;
      |         ^~~~~~~~~

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

Quoted 38 lines

---
v2: move into function block instead being switch-local (Ville Syrjälä)

---
 drivers/gpu/drm/drm_edid.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -3
index 805fb004c8eb..46cee78bc175 100644
@@ -4381,6 +4381,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
 
        if (cea_revision(cea) >= 3) {
                int i, start, end;
+               int sad_count;
 
                if (cea_db_offsets(cea, &start, &end)) {
                        start = 0;
@@ -4392,8 +4393,6 @@ 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:
                                /* Audio Data Block, contains SADs */
                                sad_count = min(dbl / 3, 15 - total_sad_count);
--

2.20.1

--
Kees Cook

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/202003060930.DDCCB6659%40keescook.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw
Quoted 11 lines · Nick Desaulniers
Quoted 8 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

Quoted 2 lines

That's not good, have you filed a bug against Clang yet? It should at least warn when the corresponding stack init flag is set.

D'oh, link is below.

Quoted 64 lines
Quoted 11 lines

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, lift such variables up into the next code block.

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]

Quoted 6 lines
 4395 |     int sad_count;
      |         ^~~~~~~~~

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

Quoted 31 lines

---
v2: move into function block instead being switch-local (Ville Syrjälä)

---
 drivers/gpu/drm/drm_edid.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -3
index 805fb004c8eb..46cee78bc175 100644
@@ -4381,6 +4381,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
 
        if (cea_revision(cea) >= 3) {
                int i, start, end;
+               int sad_count;
 
                if (cea_db_offsets(cea, &start, &end)) {
                        start = 0;
@@ -4392,8 +4393,6 @@ 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:
                                /* Audio Data Block, contains SADs */
                                sad_count = min(dbl / 3, 15 - total_sad_count);
--

2.20.1

Quoted 7 lines

--
Kees Cook

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/202003060930.DDCCB6659%40keescook.

--
Thanks,
~Nick Desaulniers

Signature · 2 lines
Thanks,
~Nick Desaulniers
#3 lore raw
In reply to Kees Cook
Quoted 17 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, lift such variables up into the next code block.

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]

Quoted 6 lines
 4395 |     int sad_count;
      |         ^~~~~~~~~

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

Thanks for your patch, applied to drm-misc-next.
-Daniel

Quoted 33 lines

---
v2: move into function block instead being switch-local (Ville Syrjälä)

---
 drivers/gpu/drm/drm_edid.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -2
index 805fb004c8eb..46cee78bc175 100644
@@ -4381,6 +4381,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
 
 	if (cea_revision(cea) >= 3) {
 		int i, start, end;
+		int sad_count;
 
 		if (cea_db_offsets(cea, &start, &end)) {
 			start = 0;
@@ -4392,8 +4393,6 @@ 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:
 				/* Audio Data Block, contains SADs */
 				sad_count = min(dbl / 3, 15 - total_sad_count);
Signature · 5 lines
2.20.1


-- 
Kees Cook
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel