[PATCH v5] LoongArch: Fix CONFIG_CMDLINE_EXTEND and CONFIG_CMDLINE_BOOTLOADER handling

From: Huacai Chen
Date: Tue Jul 18 2023 - 11:34:49 EST


From: Zhihong Dong <donmor3000@xxxxxxxxxxx>

Fix CONFIG_CMDLINE_EXTEND and CONFIG_CMDLINE_BOOTLOADER handling. The
touched function is bootcmdline_init(). There's already code handling
CONFIG_CMDLINE_FORCE that replaces boot_command_line with CONFIG_CMDLINE
and immediately `goto out`. There should be some similar logic to handle
CONFIG_CMDLINE_EXTEND and CONFIG_CMDLINE_BOOTLOADER, so this patch add
some code to fix it.

Signed-off-by: Zhihong Dong <donmor3000@xxxxxxxxxxx>
Signed-off-by: Huacai Chen <chenhuacai@xxxxxxxxxxx>
---
v4 -> v5: Update commit message and adjust the code logic.
v3 -> v4: Make CONFIG_CMDLINE appended to the end of command line (Huacai);
Removed unnecessary #ifdef since CONFIG_CMDLINE is always a string on
LoongArch
Reworded comments
Reworded the subject of commit message (Huacai)
v2 -> v3: Reworded the commit message again to make it imperative (Ruoyao)
v1 -> v2: Reworded the commit message so it's more imperative (Markus);
Added `goto out` to FDT part (Huacai)

arch/loongarch/kernel/setup.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
index 95e6b579dfdd..5a6f61ed567f 100644
--- a/arch/loongarch/kernel/setup.c
+++ b/arch/loongarch/kernel/setup.c
@@ -332,9 +332,25 @@ static void __init bootcmdline_init(char **cmdline_p)
strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);

strlcat(boot_command_line, init_command_line, COMMAND_LINE_SIZE);
+ goto out;
}
#endif

+ /*
+ * Append built-in command line to the bootloader command line if
+ * CONFIG_CMDLINE_EXTEND is enabled.
+ */
+ if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) && CONFIG_CMDLINE[0]) {
+ strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
+ strlcat(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+ }
+
+ /*
+ * Use built-in command line if the bootloader command line is empty.
+ */
+ if ((IS_ENABLED(CONFIG_CMDLINE_BOOTLOADER) && !boot_command_line[0])
+ strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+
out:
*cmdline_p = boot_command_line;
}
--
2.39.3