Skip to content

Commit 4d94f91

Browse files
mrutland-armmasahir0y
authored andcommitted
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; | | ^~~~~ Signed-off-by: Mark Rutland <[email protected]> [arnd: don't add a duplicate flag to the default set, update changelog] Signed-off-by: Arnd Bergmann <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> Tested-by: Sedat Dilek <[email protected]> # LLVM/Clang v13.0.0 (x86-64) Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 1344794 commit 4d94f91

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ HOSTCXX = g++
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[])
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 == '*') {

0 commit comments

Comments
 (0)