* [PATCH] init: Use ARRAY_SIZE() in unknown_bootoption()
@ 2026-11-18 0:00 Thorsten Blum
2026-11-18 0:40 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-11-18 0:00 UTC (permalink / raw)
To: Andrew Morton, Masami Hiramatsu (Google), Thorsten Blum,
Christian Brauner, Sang-Heon Jeon, Breno Leitao,
Wilson Felipe Pereira
Cc: linux-kernel
Remove the NULL terminator from the bootloader array, make its entries
const, and use ARRAY_SIZE() as the loop bound. Also reuse the for loop
index i instead of redeclaring it multiple times.
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
init/main.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/init/main.c b/init/main.c
index 2011e09439de..5543576c9c29 100644
--- a/init/main.c
+++ b/init/main.c
@@ -576,7 +576,8 @@ static int __init unknown_bootoption(char *param, char *val,
* 1. LILO/Grub pass "BOOT_IMAGE=...";
* 2. kexec/kdump (kexec-tools) pass "kexec".
*/
- const char *bootloader[] = { "BOOT_IMAGE=", "kexec", NULL };
+ const char * const bootloader[] = { "BOOT_IMAGE=", "kexec" };
+ unsigned int i;
/* Handle params aliased to sysctls */
if (sysctl_is_alias(param))
@@ -585,7 +586,7 @@ static int __init unknown_bootoption(char *param, char *val,
repair_env_string(param, val);
/* Handle bootloader identifier */
- for (int i = 0; bootloader[i]; i++) {
+ for (i = 0; i < ARRAY_SIZE(bootloader); i++) {
if (strstarts(param, bootloader[i]))
return 0;
}
@@ -603,7 +604,6 @@ static int __init unknown_bootoption(char *param, char *val,
if (val) {
/* Environment option */
- unsigned int i;
for (i = 0; envp_init[i]; i++) {
if (!strncmp(param, envp_init[i], len+1))
break;
@@ -615,7 +615,6 @@ static int __init unknown_bootoption(char *param, char *val,
envp_init[i] = param;
} else {
/* Command line option */
- unsigned int i;
for (i = 0; argv_init[i]; i++) {
if (i == MAX_INIT_ARGS) {
panic_later = "init";
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] init: Use ARRAY_SIZE() in unknown_bootoption()
2026-11-18 0:00 [PATCH] init: Use ARRAY_SIZE() in unknown_bootoption() Thorsten Blum
@ 2026-11-18 0:40 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2026-11-18 0:40 UTC (permalink / raw)
To: Thorsten Blum
Cc: Masami Hiramatsu (Google), Christian Brauner, Sang-Heon Jeon,
Breno Leitao, Wilson Felipe Pereira, linux-kernel
On Wed, 18 Nov 2026 01:00:36 +0100 Thorsten Blum <blum@kernel.org> wrote:
> Remove the NULL terminator from the bootloader array, make its entries
> const, and use ARRAY_SIZE() as the loop bound. Also reuse the for loop
> index i instead of redeclaring it multiple times.
>
> ...
>
> --- a/init/main.c
> +++ b/init/main.c
> @@ -576,7 +576,8 @@ static int __init unknown_bootoption(char *param, char *val,
> * 1. LILO/Grub pass "BOOT_IMAGE=...";
> * 2. kexec/kdump (kexec-tools) pass "kexec".
> */
> - const char *bootloader[] = { "BOOT_IMAGE=", "kexec", NULL };
> + const char * const bootloader[] = { "BOOT_IMAGE=", "kexec" };
While you're in there, making this
static const char * const bootloader[] __initconst = ...
could/should/might put this into .init.rodata so its memory gets
recycled later in boot.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 0:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 0:00 [PATCH] init: Use ARRAY_SIZE() in unknown_bootoption() Thorsten Blum
2026-11-18 0:40 ` Andrew Morton
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.