History

Kbuild: use -Wdeclaration-after-statement

The kernel is moving from using `-std=gnu89` to `-std=gnu11`, permitting the use of additional C11 features such as for-loop initial declarations. One contentious aspect of C99 is that it permits mixed declarations and code, and for now at least, it seems preferable to enforce that declarations must come first. These warnings were already enabled in the kernel itself, but not for KBUILD_USERCFLAGS or the compat VDSO on arch/arm64, which uses a separate set of CFLAGS. This patch fixes an existing violation in modpost.c, which is not reported because of the missing flag in KBUILD_USERCFLAGS: | scripts/mod/modpost.c: In function ‘match’: | scripts/mod/modpost.c:837:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] | 837 | const char *endp = p + strlen(p) - 1; | | ^~~~~

Mark Rutland committed 4 years ago

Commit 4d94f911 parent 13447943 files · +6 −2Browse files

Unified · Split

3 files
  1. Makefile +2 −1
  2. arch/arm64/kernel/vdso32/Makefile +1 −0
  3. scripts/mod/modpost.c +3 −1
Makefile+2−1
@@ -432,7 +432,8 @@ HOSTCXX = g++ · 431 unmodified lines
432432 endif
433433
434434 export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
435− -O2 -fomit-frame-pointer -std=gnu89
435+ -O2 -fomit-frame-pointer -std=gnu89 \
436+ -Wdeclaration-after-statement
436437 export KBUILD_USERLDFLAGS :=
437438
438439 KBUILD_HOSTCFLAGS := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
arch/arm64/kernel/vdso32/Makefile+1−0
@@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ · 67 unmodified lines
6868 -fno-strict-aliasing -fno-common \
6969 -Werror-implicit-function-declaration \
7070 -Wno-format-security \
71+ -Wdeclaration-after-statement \
7172 -std=gnu89
7273 VDSO_CFLAGS += -O2
7374 # Some useful compiler-dependent flags from top-level Makefile
scripts/mod/modpost.c+3−1
@@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[]) · 832 unmodified lines
833833 {
834834 const char *p;
835835 while (*pat) {
836+ const char *endp;
837+
836838 p = *pat++;
837− const char *endp = p + strlen(p) - 1;
839+ endp = p + strlen(p) - 1;
838840
839841 /* "*foo*" */
840842 if (*p == '*' && *endp == '*') {