Skip to content

Commit e24cd4e

Browse files
keesgregkh
authored andcommitted
n_tty: 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/tty/n_tty.c: In function ‘__process_echoes’: drivers/tty/n_tty.c:657:18: warning: statement will never be executed [-Wswitch-unreachable] 657 | unsigned int num_chars, num_bs; | ^~~~~~~~~ [1] https://bugs.llvm.org/show_bug.cgi?id=44916 Reviewed-by: Jiri Slaby <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e587e8f commit e24cd4e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/tty/n_tty.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,9 @@ static size_t __process_echoes(struct tty_struct *tty)
654654
op = echo_buf(ldata, tail + 1);
655655

656656
switch (op) {
657+
case ECHO_OP_ERASE_TAB: {
657658
unsigned int num_chars, num_bs;
658659

659-
case ECHO_OP_ERASE_TAB:
660660
if (MASK(ldata->echo_commit) == MASK(tail + 2))
661661
goto not_yet_stored;
662662
num_chars = echo_buf(ldata, tail + 2);
@@ -687,7 +687,7 @@ static size_t __process_echoes(struct tty_struct *tty)
687687
}
688688
tail += 3;
689689
break;
690-
690+
}
691691
case ECHO_OP_SET_CANON_COL:
692692
ldata->canon_column = ldata->column;
693693
tail += 2;

0 commit comments

Comments
 (0)