Skip to content

Commit a035d55

Browse files
Makefile: Globally enable fall-through warning
Now that all the fall-through warnings have been addressed in the kernel, enable the fall-through warning globally. Also, update the deprecated.rst file to include implicit fall-through as 'deprecated' so people can be pointed to a single location for justification. Cc: Masahiro Yamada <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Michal Marek <[email protected]> Cc: Kees Cook <[email protected]> Cc: [email protected] Signed-off-by: Gustavo A. R. Silva <[email protected]>
1 parent 2defb94 commit a035d55

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Documentation/process/deprecated.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,17 @@ array may exceed the remaining memory in the stack segment. This could
119119
lead to a crash, possible overwriting sensitive contents at the end of the
120120
stack (when built without `CONFIG_THREAD_INFO_IN_TASK=y`), or overwriting
121121
memory adjacent to the stack (when built without `CONFIG_VMAP_STACK=y`)
122+
123+
Implicit switch case fall-through
124+
---------------------------------
125+
The C language allows switch cases to "fall through" when
126+
a "break" statement is missing at the end of a case. This,
127+
however, introduces ambiguity in the code, as it's not always
128+
clear if the missing break is intentional or a bug. As there
129+
have been a long list of flaws `due to missing "break" statements
130+
<https://cwe.mitre.org/data/definitions/484.html>`_, we no longer allow
131+
"implicit fall-through". In order to identify an intentional fall-through
132+
case, we have adopted the marking used by static analyzers: a comment
133+
saying `/* Fall through */`. Once the C++17 `__attribute__((fallthrough))`
134+
is more widely handled by C compilers, static analyzers, and IDEs, we can
135+
switch to using that instead.

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,9 @@ NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
843843
# warn about C99 declaration after statement
844844
KBUILD_CFLAGS += -Wdeclaration-after-statement
845845

846+
# Warn about unmarked fall-throughs in switch statement.
847+
KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough=3,)
848+
846849
# Variable Length Arrays (VLAs) should not be used anywhere in the kernel
847850
KBUILD_CFLAGS += -Wvla
848851

0 commit comments

Comments
 (0)