Skip to content

Commit b66fbbe

Browse files
mhiramatrostedt
authored andcommitted
init/bootconfig: Reorder init parameter from bootconfig and cmdline
Reorder the init parameters from bootconfig and kernel cmdline so that the kernel cmdline always be the last part of the parameters as below. " -- "[bootconfig init params][cmdline init params] This change will help us to prevent that bootconfig init params overwrite the init params which user gives in the command line. Link: https://lkml.kernel.org/r/163077085675.222577.5665176468023636160.stgit@devnote2 Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 40caa12 commit b66fbbe

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

init/main.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ static char *extra_init_args;
153153
#ifdef CONFIG_BOOT_CONFIG
154154
/* Is bootconfig on command line? */
155155
static bool bootconfig_found;
156-
static bool initargs_found;
156+
static size_t initargs_offs;
157157
#else
158158
# define bootconfig_found false
159-
# define initargs_found false
159+
# define initargs_offs 0
160160
#endif
161161

162162
static char *execute_command;
@@ -422,9 +422,9 @@ static void __init setup_boot_config(void)
422422
if (IS_ERR(err) || !bootconfig_found)
423423
return;
424424

425-
/* parse_args() stops at '--' and returns an address */
425+
/* parse_args() stops at the next param of '--' and returns an address */
426426
if (err)
427-
initargs_found = true;
427+
initargs_offs = err - tmp_cmdline;
428428

429429
if (!data) {
430430
pr_err("'bootconfig' found on command line, but no bootconfig found\n");
@@ -655,16 +655,21 @@ static void __init setup_command_line(char *command_line)
655655
* Append supplemental init boot args to saved_command_line
656656
* so that user can check what command line options passed
657657
* to init.
658+
* The order should always be
659+
* " -- "[bootconfig init-param][cmdline init-param]
658660
*/
659-
len = strlen(saved_command_line);
660-
if (initargs_found) {
661-
saved_command_line[len++] = ' ';
661+
if (initargs_offs) {
662+
len = xlen + initargs_offs;
663+
strcpy(saved_command_line + len, extra_init_args);
664+
len += ilen - 4; /* strlen(extra_init_args) */
665+
strcpy(saved_command_line + len,
666+
boot_command_line + initargs_offs - 1);
662667
} else {
668+
len = strlen(saved_command_line);
663669
strcpy(saved_command_line + len, " -- ");
664670
len += 4;
671+
strcpy(saved_command_line + len, extra_init_args);
665672
}
666-
667-
strcpy(saved_command_line + len, extra_init_args);
668673
}
669674
}
670675

0 commit comments

Comments
 (0)