init: Use ARRAY_SIZE() in unknown_bootoption()
PATCH v2 1/1 init: Use ARRAY_SIZE() in unknown_bootoption()
Remove the NULL terminator from the bootloader array, make its entries const, and use ARRAY_SIZE() as the loop bound. Make the array itself static and mark it __initconst, since it is only used during initialization.
Also reuse the loop index i instead of redeclaring it multiple times.
---
Changes in v2:
- Make bootloader[] static and mark it __initconst (Andrew)
- v1: https://lore.kernel.org/r/[email protected]/
init/main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
init/main.c +3 -4
@@ -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 }; +static const char *const bootloader[]__initconst = {"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" ;
Andrew Morton
tree notice+ init-use-array_size-in-unknown_bootoption.patch added to mm-nonmm-unstable branch
The patch titled Subject: init: Use ARRAY_SIZE() in unknown_bootoption() has been added to the -mm mm-nonmm-unstable branch. Its filename is init-use-array_size-in-unknown_bootoption.patch
The patch titled
Subject: init: Use ARRAY_SIZE() in unknown_bootoption()
has been added to the -mm mm-nonmm-unstable branch. Its filename is
init-use-array_size-in-unknown_bootoption.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/init-use-array_size-in-unknown_bootoption.patch
This patch will later appear in the mm-nonmm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Thorsten Blum <[email protected]>
Subject: init: Use ARRAY_SIZE() in unknown_bootoption()
Date: Wed, 18 Nov 2026 12:40:32 +0100
Remove the NULL terminator from the bootloader array, make its entries const, and use ARRAY_SIZE() as the loop bound. Make the array itself static and mark it __initconst, since it is only used during initialization.
Also reuse the loop index i instead of redeclaring it multiple times.
init/main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
init/main.c renamed from init/main.c~init-use-array_size-in-unknown_bootoption +3 -4
@@ -577,7 +577,8 @@ static int __init unknown_bootoption(cha* 1. LILO/Grub pass "BOOT_IMAGE=..."; * 2. kexec/kdump (kexec-tools) pass "kexec". */ -const char *bootloader[] = {"BOOT_IMAGE=" ,"kexec" ,NULL }; +static const char *const bootloader[]__initconst = {"BOOT_IMAGE=" ,"kexec" }; +unsigned int i;/* Handle params aliased to sysctls */ if (sysctl_is_alias (param))
@@ -586,7 +587,7 @@ static int __init unknown_bootoption(charepair_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 ; }
@@ -604,7 +605,6 @@ static int __init unknown_bootoption(chaif (val) {/* Environment option */ -unsigned int i;for (i =0 ; envp_init[i]; i++) {if (!strncmp (param, envp_init[i], len+1 ))break ;
@@ -616,7 +616,6 @@ static int __init unknown_bootoption(cha 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" ;
_
Patches currently in -mm which might be from [email protected] are
init-reject-bare-rodata-parameter-before-architecture-parsing.patch init-use-strscpy-in-do_initcalls.patch init-use-kmalloc-in-do_initcalls.patch init-remove-strlcat-and-sprintf-from-do_one_initcall.patch init-use-strscpy-in-initcall_blacklist.patch init-combine-blacklist-entry-allocations-in-initcall_blacklist.patch parport-use-kstrdup-in-parse_data.patch init-use-array_size-in-unknown_bootoption.patch