Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1431199ybk; Thu, 21 May 2020 06:47:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+5iR6+UuZoVHpCJ9VMQvQlgoqXCXYNLU6Y0QtuSKa2pnQD6lnMlrXsLkSr82k7c9wkaAo X-Received: by 2002:a17:906:70d:: with SMTP id y13mr3412413ejb.99.1590068877163; Thu, 21 May 2020 06:47:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590068877; cv=none; d=google.com; s=arc-20160816; b=S+SpARp3faQSoLPSBevgHcK4YWtlz5dBAp5ftex2DyORS76n1eSzIptbZjnCMAc9ID z4aYi/ApGJLnFA3RYf1zStbbA2z5NgPsbDVOjdSuv/FLZRJrYsTGwNKxKbk59qu17Pri 99OVgaMlZoO7Fi9IMnJNgc2kpieutUKKprDzGfIObbOfOcA+n8DuLfw3gYL844kPwTTW +dWTyGipDwueM34KzjLkqY6CIDzpehhfDVAmT4MWdNoKwHNN7h4t5h7orx1T36NWZHci uY4j9mpgILDfYdSrmWMcA0tHesGM08hFNKTGcY8FvU9UgHj8SsjzCktY6nWqNuSBm4kd zgJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=C4/prU+84xqXdFSG0qmF4XttASlATsiQOMbQcOQ0pNY=; b=IUFQKQrivtu+wXXqE4kR5Gv3+qj7DV62JSVh0XJRXDLEs/K7Ky4qXezHo769Jla1cv yaWDOeBTInm9kvFcaotW9XE5XrE2NrmppVifvtD4L7XhhtXv3X9VCsFq0QNZBa5buin8 WcLcsoFn/ykse9KREbwD0KzUn6hiBGPOF8weOQKVFFYO5eBNVoxPiW58P4PuDqwYOmp6 GT4Kg0H7FjTSS38k+oD+IQkHXv7avVclYH2YRjXt0p68aVTc6y+5hHBDG0WVXqWHpmgT TLTT1A4tk96MwLvv4js+/I/uisL85LfycM8HSSp8vpKFVQ0FeWiegmWNQg1jjsrYx37F +8Wg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rs2si3288510ejb.324.2020.05.21.06.47.32; Thu, 21 May 2020 06:47:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729479AbgEUNqI (ORCPT + 99 others); Thu, 21 May 2020 09:46:08 -0400 Received: from mx2.suse.de ([195.135.220.15]:49790 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727079AbgEUNqI (ORCPT ); Thu, 21 May 2020 09:46:08 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D2DB1AC40; Thu, 21 May 2020 13:46:08 +0000 (UTC) Date: Thu, 21 May 2020 15:46:04 +0200 From: Petr Mladek To: Joe Perches Cc: Andrew Morton , Chenggang Wang , linux-kernel@vger.kernel.org, Sergey Senozhatsky , Steven Rostedt Subject: Re: [RFC PATCH 2/2] init: Allow multi-line output of kernel command line Message-ID: <20200521134604.GE8397@linux-b0ei> References: <2b3832fed9370f0f8dfd1ea33dddb1d05a36e265.1589916689.git.joe@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2b3832fed9370f0f8dfd1ea33dddb1d05a36e265.1589916689.git.joe@perches.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > > 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