Skip to content

Commit 27d80fa

Browse files
keestorvalds
authored andcommitted
mm/shmem.c: 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. mm/shmem.c: In function `shmem_getpage_gfp': mm/shmem.c:1816:10: warning: statement will never be executed [-Wswitch-unreachable] 1816 | loff_t i_size; | ^~~~~~ [1] https://bugs.llvm.org/show_bug.cgi?id=44916 Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: Hugh Dickins <hughd@google.com> Cc: Alexander Potapenko <glider@google.com> Link: http://lkml.kernel.org/r/20200220062312.69165-1-keescook@chromium.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1040490 commit 27d80fa

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

mm/shmem.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,17 +1812,20 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
18121812
if (shmem_huge == SHMEM_HUGE_FORCE)
18131813
goto alloc_huge;
18141814
switch (sbinfo->huge) {
1815-
loff_t i_size;
1816-
pgoff_t off;
18171815
case SHMEM_HUGE_NEVER:
18181816
goto alloc_nohuge;
1819-
case SHMEM_HUGE_WITHIN_SIZE:
1817+
case SHMEM_HUGE_WITHIN_SIZE: {
1818+
loff_t i_size;
1819+
pgoff_t off;
1820+
18201821
off = round_up(index, HPAGE_PMD_NR);
18211822
i_size = round_up(i_size_read(inode), PAGE_SIZE);
18221823
if (i_size >= HPAGE_PMD_SIZE &&
18231824
i_size >> PAGE_SHIFT >= off)
18241825
goto alloc_huge;
1825-
/* fallthrough */
1826+
1827+
fallthrough;
1828+
}
18261829
case SHMEM_HUGE_ADVISE:
18271830
if (sgp_huge == SGP_HUGE)
18281831
goto alloc_huge;

0 commit comments

Comments
 (0)