All of lore.kernel.org
 help / color / mirror / Atom feed
From: Justin Stitt <justinstitt@google.com>
To: Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	 Tom Rix <trix@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	Peter Zijlstra <peterz@infradead.org>,
	 "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	linux-kernel@vger.kernel.org,  llvm@lists.linux.dev,
	Justin Stitt <justinstitt@google.com>
Subject: [PATCH] init: fix -Wmissing-variable-declarations clang warning
Date: Wed, 30 Aug 2023 19:47:06 +0000	[thread overview]
Message-ID: <20230830-missingvardecl2-init-main-c-v1-1-59007a637259@google.com> (raw)

When building x86/defconfig with Clang-18 I encounter the following warning:
| init/main.c:189:13: warning: no previous extern declaration for non-static variable 'envp_init' [-Wmissing-variable-declarations]
|   189 | const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
| init/main.c:189:7: note: declare 'static' if the variable is not intended to be used outside of this translation unit
|   189 | const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };

Move the extern declaration to a header file so that the compiler can find it
when compiling init/main.c.

Add `const` qualifier to extern declaration so that the types match and
we follow the One-Definition Rule (ODR).

Link: https://github.com/ClangBuiltLinux/linux/issues/1920
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Note: build-tested only.

There's a previous RFC [1] wherein the kernel test robot reported some
build errors which lead me to creating this patch which both fixes the
errors as well as the -Wmissing-variable-declarations warning.

[1]: https://lore.kernel.org/all/20230829-missingvardecl-init-main-c-v1-1-ddf0f1a71215@google.com/

Also, get_maintainer.pl had a hard time finding folks to Cc here, not sure why.
---
 include/linux/initrd.h  | 2 ++
 init/do_mounts_initrd.c | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/initrd.h b/include/linux/initrd.h
index f1a1f4c92ded..0114f1acbb45 100644
--- a/include/linux/initrd.h
+++ b/include/linux/initrd.h
@@ -34,4 +34,6 @@ extern unsigned long __initramfs_size;
 
 void console_on_rootfs(void);
 
+extern const char *envp_init[];
+
 #endif /* __LINUX_INITRD_H */
diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
index 425f4bcf4b77..b35c1b0babc2 100644
--- a/init/do_mounts_initrd.c
+++ b/init/do_mounts_initrd.c
@@ -87,7 +87,6 @@ static void __init handle_initrd(char *root_device_name)
 {
 	struct subprocess_info *info;
 	static char *argv[] = { "linuxrc", NULL, };
-	extern char *envp_init[];
 	int error;
 
 	pr_warn("using deprecated initrd support, will be removed in 2021.\n");

---
base-commit: 706a741595047797872e669b3101429ab8d378ef
change-id: 20230830-missingvardecl2-init-main-c-93dc1013ff8a

Best regards,
--
Justin Stitt <justinstitt@google.com>


             reply	other threads:[~2023-08-30 19:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-30 19:47 Justin Stitt [this message]
2023-08-30 20:03 ` [PATCH] init: fix -Wmissing-variable-declarations clang warning Bill Wendling
  -- strict thread matches above, loose matches on Subject: below --
2023-08-31  8:18 kernel test robot
2023-08-31  8:30 kernel test robot

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=20230830-missingvardecl2-init-main-c-v1-1-59007a637259@google.com \
    --to=justinstitt@google.com \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=trix@redhat.com \
    /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.