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; | | ^~~~~
Unified · Split
| @@ -432,7 +432,8 @@ HOSTCXX = g++ · 431 unmodified lines | ||
| 432 | 432 | endif |
| 433 | 433 | |
| 434 | 434 | 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 | |
| 436 | 437 | export KBUILD_USERLDFLAGS := |
| 437 | 438 | |
| 438 | 439 | KBUILD_HOSTCFLAGS := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS) |
| @@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ · 67 unmodified lines | ||
| 68 | 68 | -fno-strict-aliasing -fno-common \ |
| 69 | 69 | -Werror-implicit-function-declaration \ |
| 70 | 70 | -Wno-format-security \ |
| 71 | + -Wdeclaration-after-statement \ | |
| 71 | 72 | -std=gnu89 |
| 72 | 73 | VDSO_CFLAGS += -O2 |
| 73 | 74 | # Some useful compiler-dependent flags from top-level Makefile |
| @@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[]) · 832 unmodified lines | ||
| 833 | 833 | { |
| 834 | 834 | const char *p; |
| 835 | 835 | while (*pat) { |
| 836 | + const char *endp; | |
| 837 | + | |
| 836 | 838 | p = *pat++; |
| 837 | − const char *endp = p + strlen(p) - 1; | |
| 839 | + endp = p + strlen(p) - 1; | |
| 838 | 840 | |
| 839 | 841 | /* "*foo*" */ |
| 840 | 842 | if (*p == '*' && *endp == '*') { |