mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] init: fix -Wmissing-variable-declarations clang warning
@ 2023-09-05 22:43 Justin Stitt
  2023-09-11 20:46 ` Nick Desaulniers
  0 siblings, 1 reply; 3+ messages in thread
From: Justin Stitt @ 2023-09-05 22:43 UTC (permalink / raw)
  To: Nathan Chancellor, Nick Desaulniers, Tom Rix
  Cc: Jens Axboe, Peter Zijlstra, Rafael J. Wysocki, linux-kernel,
	llvm, Bill Wendling, Kees Cook, Justin Stitt

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, };

Make `envp_init` static and provide `handle_initrd` its own copy.

This silences the warning and makes the code more readable as you no
longer have to track down extern definitions inside of `handle_initrd`.
It is now more self-contained.

Link: https://github.com/ClangBuiltLinux/linux/issues/1920
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
The kernel test robot didn't like v1 of this patch and I prefer Kees'
approach to simplifying this code anyways so I'm sending this v2.
Hopefully the CI builds clean (as I am locally using their repro).

Changes in v2:
- Make envp_init static and provide handle_initrd() with a copy (thanks Kees)
- Rebase onto mainline (2dde18cd1d8fa)
- Link to v1: https://lore.kernel.org/r/20230830-missingvardecl2-init-main-c-v1-1-59007a637259@google.com
---
Note: build-tested only.

It should be noted that `handle_initrd` has been marked as deprecated
and perhaps the entire thing can be removed as per it's own message:
| using deprecated initrd support, will be removed in 2021.
---
 init/do_mounts_initrd.c | 4 ++--
 init/main.c             | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
index 425f4bcf4b77..154bd0de85a6 100644
--- a/init/do_mounts_initrd.c
+++ b/init/do_mounts_initrd.c
@@ -87,7 +87,7 @@ static void __init handle_initrd(char *root_device_name)
 {
 	struct subprocess_info *info;
 	static char *argv[] = { "linuxrc", NULL, };
-	extern char *envp_init[];
+	static char *envp[] = { "HOME=/", "TERM=linux", NULL, };
 	int error;
 
 	pr_warn("using deprecated initrd support, will be removed in 2021.\n");
@@ -100,7 +100,7 @@ static void __init handle_initrd(char *root_device_name)
 	init_mkdir("/old", 0700);
 	init_chdir("/old");
 
-	info = call_usermodehelper_setup("/linuxrc", argv, envp_init,
+	info = call_usermodehelper_setup("/linuxrc", argv, envp,
 					 GFP_KERNEL, init_linuxrc, NULL, NULL);
 	if (!info)
 		return;
diff --git a/init/main.c b/init/main.c
index ad920fac325c..9a473107bb8f 100644
--- a/init/main.c
+++ b/init/main.c
@@ -186,7 +186,7 @@ static int __init set_reset_devices(char *str)
 __setup("reset_devices", set_reset_devices);
 
 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
-const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
+static const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
 static const char *panic_later, *panic_param;
 
 static bool __init obsolete_checksetup(char *line)

---
base-commit: 2dde18cd1d8fac735875f2e4987f11817cc0bc2c
change-id: 20230830-missingvardecl2-init-main-c-93dc1013ff8a

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-09-11 22:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-05 22:43 [PATCH v2] init: fix -Wmissing-variable-declarations clang warning Justin Stitt
2023-09-11 20:46 ` Nick Desaulniers
2023-09-11 20:49   ` Nick Desaulniers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®