Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1498324pxf; Fri, 26 Mar 2021 08:44:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyH48oNWx8PLwFiBfklxe8Nx8uzrzR6tQbS/ALLPQo8IWVg1qF8WpGJSK2P9xJJKLbMMirV X-Received: by 2002:a17:906:5e55:: with SMTP id b21mr16049477eju.289.1616773459193; Fri, 26 Mar 2021 08:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616773459; cv=none; d=google.com; s=arc-20160816; b=yO33bEcfLcAsp1DfxZcgQ45/pbWCf4QsSvX1AJEYXayuwWQsnhOR3sVS2Clx1ZSjvc YK1jKrui6yjF/tOcpaWziF8QAW3LZqNS6HMuzMoAx934czWHNGdIzTAt00ZVIzhFe70q PerHuUvKqGE7Dwzojv4OuFz/2y9z5THpDcU1BDshZ5N0XmV5s7imMPUe9REEimlPntLX PHv/gok/+B7YhR++67mR7Z6QP7A6z4gd0p3XgZXfLj0u1tbqdDZP7SXaN5CcXk+pciFR 6fErC++YNURgLtz6cQ1oXoGwiONSDVWkB4gujFeMJ8T87EcurVXVPu+4efpBpNFGm3lj C9Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7IdWAsb/tyG0CMJR2kGTddZUp1qBQ0s8vFGEAhqQTsw=; b=l5Ew1Dc/ISwDQ8vcWjarZlM2DfVqUpMQeXzqNqtVGsupEu8jDr63kb4EhAh5344jKp usUJUJieDzHdJC0xIKzxV3IPpde0djSvZ6IkgtysZnd49H7HgK8uip978eFHD+D4BBpn DXhmvKUzxy3+7zZDOrjr0aEO+Y5spMxyRh7N3dwAIlxN0jbCVwR8lxbuToQ/Iymo/bjl agfnuCTvqfQgnCH/ifUf3dt3PNMneX7Zs+x9xn5A029kU1MCBihNToGoAorceZI+KHGZ f1eIlp2l47AbgCtHF9eXEvXS3w21bbSAGF+JmC5NAcmJOEmU7gzSOqYCCQVoy+dywDJR ZgJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DUfi5ugO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bi21si2872492edb.439.2021.03.26.08.43.56; Fri, 26 Mar 2021 08:44:19 -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=pass header.i=@kernel.org header.s=k20201202 header.b=DUfi5ugO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230338AbhCZPnB (ORCPT + 99 others); Fri, 26 Mar 2021 11:43:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:55426 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230273AbhCZPmu (ORCPT ); Fri, 26 Mar 2021 11:42:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5666961A2A; Fri, 26 Mar 2021 15:42:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616773369; bh=vsTZ/vYOkJZ+dX5RIeYP0sX4VHZ0dMLJGNZeZ1Bm2LQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=DUfi5ugO3VGJM2909lBb9UInMPNrDa6EKQqVta1cIaa0jmi9PW3AK/KjrURwAztbo i8x5fBqV0zqtki7tKp5qsvRSp+6JN+/eJ6Ieou5FWpav1oVdXzMR9PQmnDp1YWOfOs rjJ3avEH5azOsGiVuuyxYhIiIBwrj4oZjmpnUvQIneHge5J52ma4iOUznrC66JY4V8 tPmhAAColcWAlYEXk93IiPpU/VFt/H+KOGM/w6qxjuUILfYJP2A9DdngmKH0rgvYm1 Dqclqe/hpH6HH+86ckSN06JT8aWetb7V0wJymW/nFAsU2yRrYVduN9qA2/Ow3crzZ9 +c/utZ5v2WmJQ== Received: by mail-ej1-f49.google.com with SMTP id hq27so9062961ejc.9; Fri, 26 Mar 2021 08:42:49 -0700 (PDT) X-Gm-Message-State: AOAM531frzlW8TnrAMkRBdmfmHr7h8VVjAPjKk9Q5WOpOTuQY9bKZkG7 Mvogmp9jPl4pU3ajbS+P35xe7o1ZvbA5AxrVwA== X-Received: by 2002:a17:906:7d48:: with SMTP id l8mr15784305ejp.108.1616773367877; Fri, 26 Mar 2021 08:42:47 -0700 (PDT) MIME-Version: 1.0 References: <878228ad88df38f8914c7aa25dede3ed05c50f48.1616765869.git.christophe.leroy@csgroup.eu> In-Reply-To: <878228ad88df38f8914c7aa25dede3ed05c50f48.1616765869.git.christophe.leroy@csgroup.eu> From: Rob Herring Date: Fri, 26 Mar 2021 09:42:35 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 01/17] cmdline: Add generic function to build command line. To: Christophe Leroy Cc: Will Deacon , Daniel Walker , Daniel Gimpelevich , "open list:GENERIC INCLUDE/ASM HEADER FILES" , devicetree@vger.kernel.org, linuxppc-dev , "linux-kernel@vger.kernel.org" , linux-arm-kernel , microblaze , "open list:MIPS" , nios2 , Openrisc , linux-hexagon@vger.kernel.org, linux-riscv , X86 ML , linux-xtensa@linux-xtensa.org, SH-Linux , sparclinux Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 26, 2021 at 7:44 AM Christophe Leroy wrote: > > This code provides architectures with a way to build command line > based on what is built in the kernel and what is handed over by the > bootloader, based on selected compile-time options. Note that I have this patch pending: https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20210316193820.3137-1-alex@ghiti.fr/ It's going to need to be adapted for this. I've held off applying to see if this gets settled. > > Signed-off-by: Christophe Leroy > --- > v3: > - Addressed comments from Will > - Added capability to have src == dst > --- > include/linux/cmdline.h | 57 +++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 57 insertions(+) > create mode 100644 include/linux/cmdline.h > > diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h > new file mode 100644 > index 000000000000..dea87edd41be > --- /dev/null > +++ b/include/linux/cmdline.h > @@ -0,0 +1,57 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _LINUX_CMDLINE_H > +#define _LINUX_CMDLINE_H > + > +#include > + > +/* Allow architectures to override strlcat, powerpc can't use strings so early */ > +#ifndef cmdline_strlcat > +#define cmdline_strlcat strlcat > +#endif > + > +/* > + * This function will append or prepend a builtin command line to the command > + * line provided by the bootloader. Kconfig options can be used to alter > + * the behavior of this builtin command line. > + * @dst: The destination of the final appended/prepended string. > + * @src: The starting string or NULL if there isn't one. > + * @len: the length of dest buffer. > + */ > +static __always_inline void __cmdline_build(char *dst, const char *src, size_t len) > +{ > + if (!len || src == dst) > + return; > + > + if (IS_ENABLED(CONFIG_CMDLINE_FORCE) || !src) { > + dst[0] = 0; > + cmdline_strlcat(dst, CONFIG_CMDLINE, len); > + return; > + } > + > + if (dst != src) > + dst[0] = 0; > + > + if (IS_ENABLED(CONFIG_CMDLINE_PREPEND)) > + cmdline_strlcat(dst, CONFIG_CMDLINE " ", len); > + > + cmdline_strlcat(dst, src, len); > + > + if (IS_ENABLED(CONFIG_CMDLINE_EXTEND)) Should be APPEND. > + cmdline_strlcat(dst, " " CONFIG_CMDLINE, len); > +} > + > +#define cmdline_build(dst, src, len) do { \ Perhaps a comment why we need this to be a define. > + char *__c_dst = (dst); \ > + const char *__c_src = (src); \ > + \ > + if (__c_src == __c_dst) { \ > + static char __c_tmp[COMMAND_LINE_SIZE] __initdata = ""; \ > + \ > + cmdline_strlcat(__c_tmp, __c_src, COMMAND_LINE_SIZE); \ > + __cmdline_build(__c_dst, __c_tmp, (len)); \ > + } else { \ > + __cmdline_build(__c_dst, __c_src, (len)); \ > + } \ > +} while (0) > + > +#endif /* _LINUX_CMDLINE_H */ > -- > 2.25.0 >