All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: Masahiro Yamada <masahiroy@kernel.org>
Cc: alexs@kernel.org, arnd@arndb.de, arnd@kernel.org,
	dsterba@suse.com, elver@google.com, jani.nikula@intel.com,
	linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org,
	linux-kernel@vger.kernel.org, llvm@lists.linux.dev,
	mark.rutland@arm.com, ndesaulniers@google.com, ojeda@kernel.org,
	torvalds@linux-foundation.org
Subject: [PATCH 2/4] [v4] Kbuild: use -Wdeclaration-after-statement
Date: Tue,  8 Mar 2022 22:56:13 +0100	[thread overview]
Message-ID: <20220308215615.14183-3-arnd@kernel.org> (raw)
In-Reply-To: <20220308215615.14183-1-arnd@kernel.org>

From: Mark Rutland <mark.rutland@arm.com>

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 <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>
---
[v4]
  move ahead of actual std=gnu11 change
---
 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 a82095c69fdd..c791bfd5a471 100644
--- a/Makefile
+++ b/Makefile
@@ -432,7 +432,8 @@ HOSTCXX	= g++
 endif
 
 KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
-			 -O2 -fomit-frame-pointer -std=gnu89
+			 -O2 -fomit-frame-pointer -std=gnu89 \
+			 -Wdeclaration-after-statement
 KBUILD_USERCFLAGS  := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS)
 KBUILD_USERLDFLAGS := $(USERLDFLAGS)
 
diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
index 6c01b63ff56d..f46457f1f4f0 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=gnu89
 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


  parent reply	other threads:[~2022-03-08 21:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08 21:56 [PATCH 0/4] [v4] Kbuild: std=gnu11 changes Arnd Bergmann
2022-03-08 21:56 ` [PATCH 1/4] [v4] Kbuild: add -Wno-shift-negative-value where -Wextra is used Arnd Bergmann
2022-03-09  8:19   ` Jani Nikula
2022-03-09 16:47   ` David Sterba
2022-03-08 21:56 ` Arnd Bergmann [this message]
2022-03-08 21:56 ` [PATCH 3/4] [v4] Kbuild: move to -std=gnu11 Arnd Bergmann
2022-03-08 21:56 ` [PATCH 4/4] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS Arnd Bergmann
2022-03-09  0:09 ` [PATCH 0/4] [v4] Kbuild: std=gnu11 changes Linus Torvalds
2022-03-09  2:16   ` Masahiro Yamada
2022-03-09  9:18     ` Masahiro Yamada
2022-03-10  0:06       ` Nathan Chancellor
2022-03-11  1:00         ` Sedat Dilek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220308215615.14183-3-arnd@kernel.org \
    --to=arnd@kernel.org \
    --cc=alexs@kernel.org \
    --cc=arnd@arndb.de \
    --cc=dsterba@suse.com \
    --cc=elver@google.com \
    --cc=jani.nikula@intel.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mark.rutland@arm.com \
    --cc=masahiroy@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=ojeda@kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.