diff mbox series

[2/3] treewide: use -Wdeclaration-after-statement

Message ID 20220301145233.3689119-2-arnd@kernel.org (mailing list archive)
State New
Headers show
Series [1/3,v3] Kbuild: move to -std=gnu11 | expand

Commit Message

Arnd Bergmann March 1, 2022, 2:52 p.m. UTC
From: Mark Rutland <mark.rutland@arm.com>

In a subsequent patch we'll move the kernel 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 disabled 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 <mark.rutland@arm.com>
[arnd: don't add a duplicate flag to the default set, update changelog]
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 Makefile                          | 3 ++-
 arch/arm64/kernel/vdso32/Makefile | 1 +
 scripts/mod/modpost.c             | 4 +++-
 3 files changed, 6 insertions(+), 2 deletions(-)

Comments

Nathan Chancellor March 1, 2022, 4:54 p.m. UTC | #1
On Tue, Mar 01, 2022 at 03:52:32PM +0100, Arnd Bergmann wrote:
> From: Mark Rutland <mark.rutland@arm.com>
> 
> In a subsequent patch we'll move the kernel 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 disabled 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 <mark.rutland@arm.com>
> [arnd: don't add a duplicate flag to the default set, update changelog]
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  Makefile                          | 3 ++-
>  arch/arm64/kernel/vdso32/Makefile | 1 +
>  scripts/mod/modpost.c             | 4 +++-
>  3 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 94fa9a849a7a..37ef6a555dcd 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -432,7 +432,8 @@ HOSTCXX	= g++
>  endif
>  
>  export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> -			      -O2 -fomit-frame-pointer -std=gnu89
> +			    -O2 -fomit-frame-pointer -std=gnu89 \
> +			    -Wdeclaration-after-statement
>  export KBUILD_USERLDFLAGS :=
>  
>  KBUILD_HOSTCFLAGS   := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
> diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> index 9378ea055bf2..ed181bedbffc 100644
> --- a/arch/arm64/kernel/vdso32/Makefile
> +++ b/arch/arm64/kernel/vdso32/Makefile
> @@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
>                 -fno-strict-aliasing -fno-common \
>                 -Werror-implicit-function-declaration \
>                 -Wno-format-security \
> +               -Wdeclaration-after-statement \
>                 -std=gnu11
>  VDSO_CFLAGS  += -O2
>  # Some useful compiler-dependent flags from top-level Makefile
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 6bfa33217914..fe693304b120 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[])
>  {
>  	const char *p;
>  	while (*pat) {
> +		const char *endp;
> +
>  		p = *pat++;
> -		const char *endp = p + strlen(p) - 1;
> +		endp = p + strlen(p) - 1;
>  
>  		/* "*foo*" */
>  		if (*p == '*' && *endp == '*') {
> -- 
> 2.29.2
> 
>
Nick Desaulniers March 1, 2022, 7:57 p.m. UTC | #2
On Tue, Mar 1, 2022 at 6:52 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Mark Rutland <mark.rutland@arm.com>
>
> In a subsequent patch we'll move the kernel 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 disabled 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 <mark.rutland@arm.com>
> [arnd: don't add a duplicate flag to the default set, update changelog]
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Thanks for the patches!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>  Makefile                          | 3 ++-
>  arch/arm64/kernel/vdso32/Makefile | 1 +
>  scripts/mod/modpost.c             | 4 +++-
>  3 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 94fa9a849a7a..37ef6a555dcd 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -432,7 +432,8 @@ HOSTCXX     = g++
>  endif
>
>  export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> -                             -O2 -fomit-frame-pointer -std=gnu89
> +                           -O2 -fomit-frame-pointer -std=gnu89 \
> +                           -Wdeclaration-after-statement
>  export KBUILD_USERLDFLAGS :=
>
>  KBUILD_HOSTCFLAGS   := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
> diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> index 9378ea055bf2..ed181bedbffc 100644
> --- a/arch/arm64/kernel/vdso32/Makefile
> +++ b/arch/arm64/kernel/vdso32/Makefile
> @@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
>                 -fno-strict-aliasing -fno-common \
>                 -Werror-implicit-function-declaration \
>                 -Wno-format-security \
> +               -Wdeclaration-after-statement \
>                 -std=gnu11
>  VDSO_CFLAGS  += -O2
>  # Some useful compiler-dependent flags from top-level Makefile
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 6bfa33217914..fe693304b120 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[])
>  {
>         const char *p;
>         while (*pat) {
> +               const char *endp;
> +
>                 p = *pat++;
> -               const char *endp = p + strlen(p) - 1;
> +               endp = p + strlen(p) - 1;
>
>                 /* "*foo*" */
>                 if (*p == '*' && *endp == '*') {
> --
> 2.29.2
>
Nick Desaulniers March 1, 2022, 8:06 p.m. UTC | #3
On Tue, Mar 1, 2022 at 11:57 AM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> On Tue, Mar 1, 2022 at 6:52 AM Arnd Bergmann <arnd@kernel.org> wrote:
> >
> > From: Mark Rutland <mark.rutland@arm.com>
> >
> > In a subsequent patch we'll move the kernel 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 disabled 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 <mark.rutland@arm.com>
> > [arnd: don't add a duplicate flag to the default set, update changelog]
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> Thanks for the patches!
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

That said, there's a few additional places that reset KBUILD_CFLAGS.
$ git grep -rn "KBUILD_CFLAGS :=" | grep -v filter-out | grep -v subst
arch/mips/boot/compressed/Makefile:30:KBUILD_CFLAGS :=
$(KBUILD_CFLAGS) -D__KERNEL__ -D__DISABLE_EXPORTS \
arch/mips/vdso/Makefile:115:$(obj-vdso): KBUILD_CFLAGS :=
$(cflags-vdso) $(native-abi)
arch/mips/vdso/Makefile:144:$(obj-vdso-o32): KBUILD_CFLAGS :=
$(cflags-vdso) -mabi=32
arch/mips/vdso/Makefile:184:$(obj-vdso-n32): KBUILD_CFLAGS :=
$(cflags-vdso) -mabi=n32
arch/parisc/boot/compressed/Makefile:17:KBUILD_CFLAGS := -D__KERNEL__
-O2 -DBOOTLOADER
arch/s390/boot/Makefile:13:KBUILD_CFLAGS := $(KBUILD_CFLAGS_DECOMPRESSOR)
arch/s390/boot/compressed/Makefile:23:KBUILD_CFLAGS :=
$(KBUILD_CFLAGS_DECOMPRESSOR)
arch/s390/purgatory/Makefile:24:KBUILD_CFLAGS := -fno-strict-aliasing
-Wall -Wstrict-prototypes
arch/x86/boot/compressed/Makefile:35:KBUILD_CFLAGS := -m$(BITS) -O2
$(CLANG_FLAGS)

The parisc, s390, and x86 cases look like true positives to me (mips
looks fine FWICT).  I didn't want to nack the patch for being
incomplete, but it's not necessarily treewide.


>
> > ---
> >  Makefile                          | 3 ++-
> >  arch/arm64/kernel/vdso32/Makefile | 1 +
> >  scripts/mod/modpost.c             | 4 +++-
> >  3 files changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/Makefile b/Makefile
> > index 94fa9a849a7a..37ef6a555dcd 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -432,7 +432,8 @@ HOSTCXX     = g++
> >  endif
> >
> >  export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> > -                             -O2 -fomit-frame-pointer -std=gnu89
> > +                           -O2 -fomit-frame-pointer -std=gnu89 \
> > +                           -Wdeclaration-after-statement
> >  export KBUILD_USERLDFLAGS :=
> >
> >  KBUILD_HOSTCFLAGS   := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
> > diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> > index 9378ea055bf2..ed181bedbffc 100644
> > --- a/arch/arm64/kernel/vdso32/Makefile
> > +++ b/arch/arm64/kernel/vdso32/Makefile
> > @@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
> >                 -fno-strict-aliasing -fno-common \
> >                 -Werror-implicit-function-declaration \
> >                 -Wno-format-security \
> > +               -Wdeclaration-after-statement \
> >                 -std=gnu11
> >  VDSO_CFLAGS  += -O2
> >  # Some useful compiler-dependent flags from top-level Makefile
> > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> > index 6bfa33217914..fe693304b120 100644
> > --- a/scripts/mod/modpost.c
> > +++ b/scripts/mod/modpost.c
> > @@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[])
> >  {
> >         const char *p;
> >         while (*pat) {
> > +               const char *endp;
> > +
> >                 p = *pat++;
> > -               const char *endp = p + strlen(p) - 1;
> > +               endp = p + strlen(p) - 1;
> >
> >                 /* "*foo*" */
> >                 if (*p == '*' && *endp == '*') {
> > --
> > 2.29.2
> >
>
>
> --
> Thanks,
> ~Nick Desaulniers
Linus Torvalds March 1, 2022, 8:20 p.m. UTC | #4
On Tue, Mar 1, 2022 at 12:06 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> That said, there's a few additional places that reset KBUILD_CFLAGS.

Yeah, the boot code and vdso code often sets its own private flags,
because it's _so_ different.

The generic kernel CFLAGS often don't work at all, because that code
may be doing some truly horrendous things.

So I agree that this may not catch all the kernel code, but I don't
think it's much of a problem.

             Linus
Nick Desaulniers March 1, 2022, 8:28 p.m. UTC | #5
On Tue, Mar 1, 2022 at 12:20 PM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> On Tue, Mar 1, 2022 at 12:06 PM Nick Desaulniers
> <ndesaulniers@google.com> wrote:
> >
> > That said, there's a few additional places that reset KBUILD_CFLAGS.
>
> Yeah, the boot code and vdso code often sets its own private flags,
> because it's _so_ different.
>
> The generic kernel CFLAGS often don't work at all, because that code
> may be doing some truly horrendous things.
>
> So I agree that this may not catch all the kernel code, but I don't
> think it's much of a problem.

Agreed; they can still mirror the style imposed by
-Wdeclaration-after-statement like the rest of the codebase though.
Masahiro Yamada March 3, 2022, 12:44 a.m. UTC | #6
On Tue, Mar 1, 2022 at 11:52 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Mark Rutland <mark.rutland@arm.com>
>
> In a subsequent patch we'll move the kernel from using `-std=gnu89` to


Precisely speaking,
"In a subsequent patch we'll move the userspace tools ..."

The kernel part was done by 1/3.



> `-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 disabled in the kernel itself, but not

Is this the opposite?

"These warnings were already _enabled_ in the kernel itself, ..."




If you have a chance to resend this,
can you please rebase on top of kbuild/for-next?

This is not applicable due to the conflict with:
https://patchwork.kernel.org/project/linux-kbuild/patch/20220201213542.2808035-1-quic_eberman@quicinc.com/






> 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 <mark.rutland@arm.com>
> [arnd: don't add a duplicate flag to the default set, update changelog]
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  Makefile                          | 3 ++-
>  arch/arm64/kernel/vdso32/Makefile | 1 +
>  scripts/mod/modpost.c             | 4 +++-
>  3 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 94fa9a849a7a..37ef6a555dcd 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -432,7 +432,8 @@ HOSTCXX     = g++
>  endif
>
>  export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> -                             -O2 -fomit-frame-pointer -std=gnu89
> +                           -O2 -fomit-frame-pointer -std=gnu89 \
> +                           -Wdeclaration-after-statement
>  export KBUILD_USERLDFLAGS :=
>
>  KBUILD_HOSTCFLAGS   := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
> diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> index 9378ea055bf2..ed181bedbffc 100644
> --- a/arch/arm64/kernel/vdso32/Makefile
> +++ b/arch/arm64/kernel/vdso32/Makefile
> @@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
>                 -fno-strict-aliasing -fno-common \
>                 -Werror-implicit-function-declaration \
>                 -Wno-format-security \
> +               -Wdeclaration-after-statement \
>                 -std=gnu11
>  VDSO_CFLAGS  += -O2
>  # Some useful compiler-dependent flags from top-level Makefile
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 6bfa33217914..fe693304b120 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[])
>  {
>         const char *p;
>         while (*pat) {
> +               const char *endp;
> +
>                 p = *pat++;
> -               const char *endp = p + strlen(p) - 1;
> +               endp = p + strlen(p) - 1;
>
>                 /* "*foo*" */
>                 if (*p == '*' && *endp == '*') {
> --
> 2.29.2
>
Sedat Dilek March 4, 2022, 11:29 a.m. UTC | #7
On Tue, Mar 1, 2022 at 4:59 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Mark Rutland <mark.rutland@arm.com>
>
> In a subsequent patch we'll move the kernel 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 disabled 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 <mark.rutland@arm.com>
> [arnd: don't add a duplicate flag to the default set, update changelog]
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

I was able to build and boot on bare metal.

No new warnings in my build-log here after switching to -std=gnu11.

Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v13.0.0 x86-64

- sed@ -

> ---
>  Makefile                          | 3 ++-
>  arch/arm64/kernel/vdso32/Makefile | 1 +
>  scripts/mod/modpost.c             | 4 +++-
>  3 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 94fa9a849a7a..37ef6a555dcd 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -432,7 +432,8 @@ HOSTCXX     = g++
>  endif
>
>  export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> -                             -O2 -fomit-frame-pointer -std=gnu89
> +                           -O2 -fomit-frame-pointer -std=gnu89 \
> +                           -Wdeclaration-after-statement
>  export KBUILD_USERLDFLAGS :=
>
>  KBUILD_HOSTCFLAGS   := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
> diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> index 9378ea055bf2..ed181bedbffc 100644
> --- a/arch/arm64/kernel/vdso32/Makefile
> +++ b/arch/arm64/kernel/vdso32/Makefile
> @@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
>                 -fno-strict-aliasing -fno-common \
>                 -Werror-implicit-function-declaration \
>                 -Wno-format-security \
> +               -Wdeclaration-after-statement \
>                 -std=gnu11
>  VDSO_CFLAGS  += -O2
>  # Some useful compiler-dependent flags from top-level Makefile
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 6bfa33217914..fe693304b120 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[])
>  {
>         const char *p;
>         while (*pat) {
> +               const char *endp;
> +
>                 p = *pat++;
> -               const char *endp = p + strlen(p) - 1;
> +               endp = p + strlen(p) - 1;
>
>                 /* "*foo*" */
>                 if (*p == '*' && *endp == '*') {
> --
> 2.29.2
>
Sedat Dilek March 6, 2022, 10:03 a.m. UTC | #8
On Fri, Mar 4, 2022 at 12:29 PM Sedat Dilek <sedat.dilek@gmail.com> wrote:
>
> On Tue, Mar 1, 2022 at 4:59 PM Arnd Bergmann <arnd@kernel.org> wrote:
> >
> > From: Mark Rutland <mark.rutland@arm.com>
> >
> > In a subsequent patch we'll move the kernel 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 disabled 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 <mark.rutland@arm.com>
> > [arnd: don't add a duplicate flag to the default set, update changelog]
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> I was able to build and boot on bare metal.
>
> No new warnings in my build-log here after switching to -std=gnu11.
>
> Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v13.0.0 x86-64
>

I have re-tested with Debian's LLVM/Clang v14.0.0-rc2.

Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v14.0.0-rc2 (x86-64)

- sed@ -

> - sed@ -
>
> > ---
> >  Makefile                          | 3 ++-
> >  arch/arm64/kernel/vdso32/Makefile | 1 +
> >  scripts/mod/modpost.c             | 4 +++-
> >  3 files changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/Makefile b/Makefile
> > index 94fa9a849a7a..37ef6a555dcd 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -432,7 +432,8 @@ HOSTCXX     = g++
> >  endif
> >
> >  export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> > -                             -O2 -fomit-frame-pointer -std=gnu89
> > +                           -O2 -fomit-frame-pointer -std=gnu89 \
> > +                           -Wdeclaration-after-statement
> >  export KBUILD_USERLDFLAGS :=
> >
> >  KBUILD_HOSTCFLAGS   := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
> > diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> > index 9378ea055bf2..ed181bedbffc 100644
> > --- a/arch/arm64/kernel/vdso32/Makefile
> > +++ b/arch/arm64/kernel/vdso32/Makefile
> > @@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
> >                 -fno-strict-aliasing -fno-common \
> >                 -Werror-implicit-function-declaration \
> >                 -Wno-format-security \
> > +               -Wdeclaration-after-statement \
> >                 -std=gnu11
> >  VDSO_CFLAGS  += -O2
> >  # Some useful compiler-dependent flags from top-level Makefile
> > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> > index 6bfa33217914..fe693304b120 100644
> > --- a/scripts/mod/modpost.c
> > +++ b/scripts/mod/modpost.c
> > @@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[])
> >  {
> >         const char *p;
> >         while (*pat) {
> > +               const char *endp;
> > +
> >                 p = *pat++;
> > -               const char *endp = p + strlen(p) - 1;
> > +               endp = p + strlen(p) - 1;
> >
> >                 /* "*foo*" */
> >                 if (*p == '*' && *endp == '*') {
> > --
> > 2.29.2
> >
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 94fa9a849a7a..37ef6a555dcd 100644
--- a/Makefile
+++ b/Makefile
@@ -432,7 +432,8 @@  HOSTCXX	= g++
 endif
 
 export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
-			      -O2 -fomit-frame-pointer -std=gnu89
+			    -O2 -fomit-frame-pointer -std=gnu89 \
+			    -Wdeclaration-after-statement
 export KBUILD_USERLDFLAGS :=
 
 KBUILD_HOSTCFLAGS   := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
index 9378ea055bf2..ed181bedbffc 100644
--- a/arch/arm64/kernel/vdso32/Makefile
+++ b/arch/arm64/kernel/vdso32/Makefile
@@ -68,6 +68,7 @@  VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                -fno-strict-aliasing -fno-common \
                -Werror-implicit-function-declaration \
                -Wno-format-security \
+               -Wdeclaration-after-statement \
                -std=gnu11
 VDSO_CFLAGS  += -O2
 # Some useful compiler-dependent flags from top-level Makefile
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 6bfa33217914..fe693304b120 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -833,8 +833,10 @@  static int match(const char *sym, const char * const pat[])
 {
 	const char *p;
 	while (*pat) {
+		const char *endp;
+
 		p = *pat++;
-		const char *endp = p + strlen(p) - 1;
+		endp = p + strlen(p) - 1;
 
 		/* "*foo*" */
 		if (*p == '*' && *endp == '*') {