All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arvind Sankar <nivedita@alum.mit.edu>
To: Joe Perches <joe@perches.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Chenggang Wang <wangchenggang@vivo.com>,
	linux-kernel@vger.kernel.org, Petr Mladek <pmladek@suse.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [RFC PATCH 2/2] init: Allow multi-line output of kernel command line
Date: Thu, 21 May 2020 11:59:31 -0400	[thread overview]
Message-ID: <20200521155931.GA568639@rani.riverdale.lan> (raw)
In-Reply-To: <2b3832fed9370f0f8dfd1ea33dddb1d05a36e265.1589916689.git.joe@perches.com>

On Tue, May 19, 2020 at 12:42:35PM -0700, 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;
> +		}
> +		saved_char = line[last_pos - line];
> +		line[last_pos - line] = 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;
> +	}
> +
> +	pr_notice("%s: %s\n", prefix, line);
> +#endif

I might be missing something, but this seems broken:
(1) If there is a ' ', the memchr will set pos to the ' ' the first time
through the inner loop, and then go into an infinite loop? You want
memrchr here but the kernel doesn't seem to have one.
(2) If there are no remaining ' 's pos will be NULL and the last two
lines in the outer loop use it -- those should be last_pos instead?
(3) Once those are fixed, you need to ensure you make progress: if
there's exactly one ' ' remaining, at the very beginning of the
remaining line, you need to print upto the PRINTK_LOG_LINE_MAX, not 0
bytes.

  parent reply	other threads:[~2020-05-21 15:59 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-19  3:29 [PATCH] init/main.c: Print all command line when boot 王程刚
2020-05-19  3:44 ` Andrew Morton
2020-05-19  5:09   ` Joe Perches
2020-05-19 14:34     ` Arvind Sankar
2020-05-19 19:42     ` [RFC PATCH 0/2] printk/init: multi-line kernel command line logging Joe Perches
2020-05-19 19:42       ` [RFC PATCH 1/2] printk: Move and rename maximum printk output line length defines Joe Perches
2020-05-21 13:49         ` Petr Mladek
2020-05-19 19:42       ` [RFC PATCH 2/2] init: Allow multi-line output of kernel command line Joe Perches
2020-05-20  4:41         ` Sergey Senozhatsky
2020-05-20  4:58           ` Joe Perches
2020-05-20 12:10             ` Sergey Senozhatsky
2020-05-20 20:36               ` Joe Perches
2020-05-21  1:00                 ` Andrew Morton
2020-05-21  2:09                   ` Joe Perches
2020-05-21  4:36                   ` Sergey Senozhatsky
2020-05-21  4:40                     ` Andrew Morton
2020-05-21 12:31                       ` Petr Mladek
2020-05-21 15:08                         ` Arvind Sankar
2020-05-21 12:48                       ` Sergey Senozhatsky
2020-05-21  4:32                 ` Sergey Senozhatsky
2020-05-21 13:46         ` Petr Mladek
2020-05-21 15:59         ` Arvind Sankar [this message]
2020-05-21 16:09           ` Joe Perches
2020-06-03  8:48         ` [init] d0bcc26c0d: BUG:kernel_hang_in_early-boot_stage,last_printk:early_console_in_setup_code kernel test robot
2020-06-03  8:48           ` [init] d0bcc26c0d: BUG:kernel_hang_in_early-boot_stage, last_printk:early_console_in_setup_code kernel test robot
2020-05-21 18:40       ` [PATCH] printk: Move and rename maximum printk output line length defines Joe Perches
2020-05-25  8:38         ` Sergey Senozhatsky
2020-05-20 14:01 ` [PATCH] init/main.c: Print all command line when boot Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200521155931.GA568639@rani.riverdale.lan \
    --to=nivedita@alum.mit.edu \
    --cc=akpm@linux-foundation.org \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=wangchenggang@vivo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.