init: fix -Wmissing-variable-declarations clang warning
PATCH 1/1 init: fix -Wmissing-variable-declarations clang warning
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).
---
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/[email protected]/
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(-)
include/linux/initrd.h +2 -0
@@ -34,4 +34,6 @@ extern unsigned long __initramfs_size;void console_on_rootfs (void ); +extern const char *envp_init[]; +#endif /* __LINUX_INITRD_H */
init/do_mounts_initrd.c +0 -1
@@ -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 <[email protected]>
Quoted 7 lines · 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, };
Quoted 6 lines
Move the extern declaration to a header file so that the compiler can find it when compiling
init/main.c.Add
constqualifier to extern declaration so that the types match and we follow the One-Definition Rule (ODR).
I'm not sure the lack of a "const" has anything to do with the ODR. C's type system isn't nearly as strict as C++'s. :-) That said, adding "const" is definitely correct.
-bw
Quoted 50 lines
Signed-off-by Justin Stitt <[email protected]>---
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/[email protected]/
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(-)include/linux/initrd.h +2
-0@@ -34,4 +34,6 @@ extern unsigned long __initramfs_size;void console_on_rootfs (void ); +extern const char *envp_init[]; +#endif /* __LINUX_INITRD_H */ init/do_mounts_initrd.c +0
-2@@ -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-93dc1013ff8aBest regards,
--
Justin Stitt <[email protected]>