Skip to content

Commit deec222

Browse files
keesdanvet
authored andcommitted
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ä) Signed-off-by: Kees Cook <[email protected]> [danvet: keep the changelog] Signed-off-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/202003060930.DDCCB6659@keescook
1 parent bd50d4a commit deec222

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/gpu/drm/drm_edid.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4434,6 +4434,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
44344434

44354435
if (cea_revision(cea) >= 3) {
44364436
int i, start, end;
4437+
int sad_count;
44374438

44384439
if (cea_db_offsets(cea, &start, &end)) {
44394440
start = 0;
@@ -4445,8 +4446,6 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
44454446
dbl = cea_db_payload_len(db);
44464447

44474448
switch (cea_db_tag(db)) {
4448-
int sad_count;
4449-
44504449
case AUDIO_BLOCK:
44514450
/* Audio Data Block, contains SADs */
44524451
sad_count = min(dbl / 3, 15 - total_sad_count);

0 commit comments

Comments
 (0)