Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1530239ybk; Thu, 21 May 2020 09:01:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUMxx0T548Z/XRQQWBpdaNgBEeMWegJyS4Nu36F66uUDstNhLBu3+oZAlCOXUZ6gDQ6wuR X-Received: by 2002:a17:906:b2c6:: with SMTP id cf6mr4209594ejb.210.1590076904956; Thu, 21 May 2020 09:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590076904; cv=none; d=google.com; s=arc-20160816; b=VxPFlQrTrvDvXv1j38wUtO2FzECxoynJrBdtfCy/TMLkTO9DQsLytO9DqwU+OjRsIC sXX8y9mZbIBPIWpIYCukB/EjIT6VvzFWeZKA5GakzYuljTjMGjVwJ9LtNMcbASSsPW8Z 9TxR6u3GhHAMBCqHBABu2gfXhDbzDXqmi5HY1F+dNfT9R9OssYIFIVjJy9Y1/Rl+iSZm KFuvALSia1PjFaeH74+sOeBA9VfXMcL8vd52ncP5gn7XjXDphMe9PC3JYJdItD7rK3FK Fs97LDb1UrmBxMcdm+Pdh8jQ6d1JV9ixNB8G8wVuDoQ6mK7Ls7k4NOCse2c8g+AFERIk Ey8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :dkim-signature; bh=07EOCluouBpl9qKeod5y2zfCi6Qn4VI7pDSmqQBWZhY=; b=O6z3npaUmpmXkXSMa4edCMt5dT6MTj/E7wEczptzwHCstOZdXgY05k1HgWIB3pWkQG 4m0uiR3UlMled2ZhTJLzWL5k6rA3CKMYBTf/2Lm03NJCj/SB0FE2VONwKyQBfS/64zcs yZDInvOExbF5oQ7E2k0rn4kNutTnIlG6SMIQzULk3DuIZ5QGSEx5Vi0rvz7hrfBQ7bFJ MGwXdMsPFExxtcrdzXfrpYS5c18DnprS8xMpz0lcVHZ6V6dZVL6/O7YdKG1xbk7cYoIU rQ9JimeV0Yanh3RJQpbPz6W8D/KCTIBP81XN50mVSUINpixkyBzmWxl6ii5WSXHS4wWJ FhtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=IXYLSXwe; 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 q8si3742136edn.307.2020.05.21.09.01.20; Thu, 21 May 2020 09:01:44 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=IXYLSXwe; 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 S1729549AbgEUP7g (ORCPT + 99 others); Thu, 21 May 2020 11:59:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726808AbgEUP7f (ORCPT ); Thu, 21 May 2020 11:59:35 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62E0AC061A0E for ; Thu, 21 May 2020 08:59:35 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id f189so7699859qkd.5 for ; Thu, 21 May 2020 08:59:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=07EOCluouBpl9qKeod5y2zfCi6Qn4VI7pDSmqQBWZhY=; b=IXYLSXwel3alWlcsiMhwa5MUFfdZp4obBq4P/b/2YO4w30NVQ8zgHX5rSFUa7o+eKK 9f1fGdDBBVc0OFqFAd/O18FcCptIn7Zkgwkub3WQVHdKq2tg26jzaUXTQEzBpX7Fu8m/ 1bw9FmOd3pz/qu1sQHTJNVghAb+fbo01KfMkmrDFGOXBneIgKVLx2hFRnFvRQLlFPp83 yv0DhcO8+RNpzXAsA4FmGhkK5z43YTbAgomjvwcbAb1m5piJTnPWn3CfDzvjA9YJUgNf Teo1AFE7BGZH2kYjSEvv5bNmPivAeFYftHh4uCjULJuA+EYFh9MRixuKfWcI33Z8t4Xg iamg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=07EOCluouBpl9qKeod5y2zfCi6Qn4VI7pDSmqQBWZhY=; b=bHAdmGO7BJ4nKvlRSaC/aS4mUiXdc1Tjt4H+cTzP6H5UrtwIe0c374nGbJw1P2BGR9 mVRRg9O5M1i8llHyMd3rkIFjCUL5L8+y3J6f9gHB+5esBpMuWL5wJlweMrPgzgtLAjry l6/jT/mf8srS+6jkGrFXztP5F5qg7CO/jGkVsAyz1XrBE14wrDgQlDO8UVJ8WcyGZSwN pR6GFRao3UftBYzEPX0uLLIgpkcFj9+do4hsySjPSnZbRWLmDgARp0Bg9NUihMQyrxxU 1jZo0js9Y94I9ozmvFKxMY3PGCX+emTEuXB2Il7c0RzeOHTXc9JEYI2UAGwAzbVuPkRN isNA== X-Gm-Message-State: AOAM531PB+JpIpfhB/7gsDM7JG6grN8xKJjDRlbDEG/5NxkC/Glsf/Si RSTdWWSiirhLJPbk3yhnEac= X-Received: by 2002:a37:9d09:: with SMTP id g9mr10683963qke.154.1590076774449; Thu, 21 May 2020 08:59:34 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id s55sm5754114qtb.92.2020.05.21.08.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 08:59:33 -0700 (PDT) From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Thu, 21 May 2020 11:59:31 -0400 To: Joe Perches Cc: Andrew Morton , Chenggang Wang , linux-kernel@vger.kernel.org, Petr Mladek , Sergey Senozhatsky , Steven Rostedt Subject: Re: [RFC PATCH 2/2] init: Allow multi-line output of kernel command line Message-ID: <20200521155931.GA568639@rani.riverdale.lan> References: <2b3832fed9370f0f8dfd1ea33dddb1d05a36e265.1589916689.git.joe@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <2b3832fed9370f0f8dfd1ea33dddb1d05a36e265.1589916689.git.joe@perches.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > > 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.