kernel: backport gnu11 upgrade
[openwrt/staging/jow.git] / target / linux / generic / backport-5.15 / 005-v5.17-01-Kbuild-use-Wdeclaration-after-statement.patch
1 From 2fd7e7f9317d3048a14026816d081b08ba98ea8e Mon Sep 17 00:00:00 2001
2 From: Mark Rutland <mark.rutland@arm.com>
3 Date: Tue, 8 Mar 2022 22:56:13 +0100
4 Subject: [PATCH 1/3] Kbuild: use -Wdeclaration-after-statement
5
6 The kernel is moving from using `-std=gnu89` to `-std=gnu11`, permitting
7 the use of additional C11 features such as for-loop initial declarations.
8
9 One contentious aspect of C99 is that it permits mixed declarations and
10 code, and for now at least, it seems preferable to enforce that
11 declarations must come first.
12
13 These warnings were already enabled in the kernel itself, but not
14 for KBUILD_USERCFLAGS or the compat VDSO on arch/arm64, which uses
15 a separate set of CFLAGS.
16
17 This patch fixes an existing violation in modpost.c, which is not
18 reported because of the missing flag in KBUILD_USERCFLAGS:
19
20 | scripts/mod/modpost.c: In function ‘match’:
21 | scripts/mod/modpost.c:837:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
22 | 837 | const char *endp = p + strlen(p) - 1;
23 | | ^~~~~
24
25 Signed-off-by: Mark Rutland <mark.rutland@arm.com>
26 [arnd: don't add a duplicate flag to the default set, update changelog]
27 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
28 Reviewed-by: Nathan Chancellor <nathan@kernel.org>
29 Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
30 Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v13.0.0 (x86-64)
31 Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
32 ---
33 Makefile | 3 ++-
34 arch/arm64/kernel/vdso32/Makefile | 1 +
35 scripts/mod/modpost.c | 4 +++-
36 3 files changed, 6 insertions(+), 2 deletions(-)
37
38 diff --git a/Makefile b/Makefile
39 index b9e0b5c604af..cfe400032f96 100644
40 --- a/Makefile
41 +++ b/Makefile
42 @@ -416,7 +416,8 @@ HOSTCXX = g++
43 endif
44
45 export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
46 - -O2 -fomit-frame-pointer -std=gnu89
47 + -O2 -fomit-frame-pointer -std=gnu89 \
48 + -Wdeclaration-after-statement
49 export KBUILD_USERLDFLAGS :=
50
51 KBUILD_HOSTCFLAGS := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
52 diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
53 index abad38c576e1..33cd7ed3f94f 100644
54 --- a/arch/arm64/kernel/vdso32/Makefile
55 +++ b/arch/arm64/kernel/vdso32/Makefile
56 @@ -76,6 +76,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
57 -fno-strict-aliasing -fno-common \
58 -Werror-implicit-function-declaration \
59 -Wno-format-security \
60 + -Wdeclaration-after-statement \
61 -std=gnu89
62 VDSO_CFLAGS += -O2
63 # Some useful compiler-dependent flags from top-level Makefile
64 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
65 index 3c27a177b28b..d2b17ed27e6e 100644
66 --- a/scripts/mod/modpost.c
67 +++ b/scripts/mod/modpost.c
68 @@ -844,8 +844,10 @@ static int match(const char *sym, const char * const pat[])
69 {
70 const char *p;
71 while (*pat) {
72 + const char *endp;
73 +
74 p = *pat++;
75 - const char *endp = p + strlen(p) - 1;
76 + endp = p + strlen(p) - 1;
77
78 /* "*foo*" */
79 if (*p == '*' && *endp == '*') {
80 --
81 2.37.2