Messages in this thread | | | Date | Thu, 21 May 2020 15:46:04 +0200 | From | Petr Mladek <> | Subject | Re: [RFC PATCH 2/2] init: Allow multi-line output of kernel command line |
| |
On Tue 2020-05-19 12:42:35, Joe Perches wrote: > ARM may have its longest possible command line larger than the longest > possible printk. > > If necessary, emit the commend line on multiple lines. > > Signed-off-by: Joe Perches <joe@perches.com> > --- > > compiled, untested > > init/main.c | 31 ++++++++++++++++++++++++++++++- > 1 file changed, 30 insertions(+), 1 deletion(-) > > diff --git a/init/main.c b/init/main.c > index b63a3c001ac4..b3ebbbc129ae 100644 > --- a/init/main.c > +++ b/init/main.c > @@ -826,6 +826,34 @@ void __init __weak arch_call_rest_init(void) > rest_init(); > } > > +static void __init print_cmdline(char *line) > +{ > +#ifdef CONFIG_PRINTK > + const char *prefix = "Kernel command line"; > + size_t len = strlen(line); > + > + while (len > PRINTK_LOG_LINE_MAX) { > + char *pos = line; > + char *last_pos = pos + PRINTK_LOG_LINE_MAX - 1; > + char saved_char; > + /* Find last space char within the maximum line length */ > + while ((pos = memchr(pos, ' ', len - (pos - line))) && > + (pos - line) < PRINTK_LOG_LINE_MAX - 1) { > + last_pos = pos; > + }
strchr() would safe the length calculation:
while ((pos = strchr(pos, ' ')) && (pos - line) < PRINTK_LOG_LINE_MAX - 1) { last_pos = pos; }
> + saved_char = line[last_pos - line]; > + line[last_pos - line] = 0;
This looks less cryptic:
saved_char = *last_pos; *last_pos = '\0';
> + pr_notice("%s: %s\n", prefix, line); > + prefix = "Kernel command line (continued)"; > + line[last_pos - line] = saved_char; > + len -= pos - line; > + line += pos - line;
'pos' might be NULL when there is no ' ' in the string. What about?
len -= last_pos - line; line = last_pos; > + } > + > + pr_notice("%s: %s\n", prefix, line); > +#endif > +}
Plus, the code should count the prefix length when splitting the line as reported by Sergey.
Best Regards, Petr
| |