Skip to contentSkip to conversation

init: Use ARRAY_SIZE() in unknown_bootoption()

PATCH Superseded Thorsten Blum 2 participants 2 messages Nov 18

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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. Also reuse the for loop index i instead of redeclaring it multiple times.

---
 init/main.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
init/main.c +3 -4
index 2011e09439de..5543576c9c29 100644
@@ -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";
#1 lore raw
Quoted 9 lines · On Wed, 18 Nov 2026 01:00:36 +0100 Thorsten Blum <[email protected]> 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.

...

init/main.c static int __init unknown_bootoption(char *param, char *val, · line 579

Quoted 5 lines
init/main.c +1 -1
@@ -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.