Received: by 10.213.65.68 with SMTP id h4csp875870imn; Sun, 18 Mar 2018 05:53:47 -0700 (PDT) X-Google-Smtp-Source: AG47ELunLpwrZLh/cDO7jtYF5ivDAmHquSQuul5Zxfkbv3HU4tE4H6SW2g8D5nrfzvLPb25UMK+x X-Received: by 10.98.218.7 with SMTP id c7mr7165045pfh.162.1521377627275; Sun, 18 Mar 2018 05:53:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521377627; cv=none; d=google.com; s=arc-20160816; b=a2m5wegVM7KqtVUeliMDJdSNYGLKA97kwn50/Pvfka9hwXvmOLDKNjdIzwRGfpeyXI YfH/JeFcLrFSykT05/XYK+g3Nam2fdJWGGDb4kbVKsItGJfD3q7IjEFEdaV+6r0ayMjh 6AvHjwvq30ES1jo+MMwhpCqwp2lpNnaS7jZkzc1yGbIFWgieSVDom22hPbUvyqcRrto1 XE8WJYCreUYCcQkKPkCtkrQ9nW45P7xil9RyEx+Ov7773Og9c92UYsH3Pcp1dDcyDTMn Xno+Gfllk3FWmErXn0jeTseQGIOLsKBMysk/zc6SuUyXAXnvG0LTCD/r3/wWJLFJb2Bb 6N9Q== 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:arc-authentication-results; bh=FslDgIxFpS5OfccK06HIkHhaAMB5k7YhAmMjfxkmDyg=; b=uLmyCql8PNaX4XKZxrYdtAJ+V0GEF/7C5qwigITKW3q1O9PqBZXMM9bJ3C08Dj+yFL 3WU3ii7i+bmS3j6bVk+bwTJrQjUecPrASFvRSCgmyJhFgsjxKfs6TcsJU+gSIyL1JNyV plwsK/kwAIAMb0UUy+ZPE9nUHPJLtJ6dIOuohCQz4x4LRkTx4j8/vL1cOMKh368FNZID FJJzQRMnGteLkqpHWCZNQJNQCk9yq61ODlWloszQtTNCwdyJhTsPZGAosXlIUYph4Rnu rx1d/C0w8x5AcIdEjgh9c+nDbaYWeFkzlZcUkSbw7EJLemaIGYEe2UUNHmQA/kZZpg26 03JA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j10si938240pfe.276.2018.03.18.05.53.33; Sun, 18 Mar 2018 05:53:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752767AbeCRMwB (ORCPT + 99 others); Sun, 18 Mar 2018 08:52:01 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:37933 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754108AbeCRMvy (ORCPT ); Sun, 18 Mar 2018 08:51:54 -0400 Received: by mail-pg0-f67.google.com with SMTP id a15so5865622pgn.5; Sun, 18 Mar 2018 05:51:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=FslDgIxFpS5OfccK06HIkHhaAMB5k7YhAmMjfxkmDyg=; b=b5HKw7400hJ6S1wCKR+zv5vI9P1IKrEACI7ihHWopCLAe03S0r8GWB3vVPJ6MGRQmf n48J6Xsx2wl13YB5LGo8UOTB7Fg5jJYYvoxlYxtRlpJ/7SEmsXi13tivlUB8lpz98AY1 exvhbOSnHpuzCnLEqcER/94Zh3haK9IaMW8bwc0QcE4TIf4WTLsmvXe/+Yy7uJlfeIze ZXusoklVB3LNASWwXubR6HTnCOYVEf/grGh7EypaEQ9cWqz5Prqk3qcb68Nh71AH8NA6 M5/9Lnl314+zDpalcTX2oAwJkOUn4K0qjgSQ9I2ptAL3qy8Uz42ltTxlTm/Vi5dvZczy +fgA== X-Gm-Message-State: AElRT7EhBPZWhAJWZ2YG5gr/gQ5uelyFE9UR4jakv1YqhzjmXHBX186Y xDWYb/1lmsdW69bBxfGF7TnBNpc= X-Received: by 10.101.96.43 with SMTP id p11mr6485993pgu.430.1521377513278; Sun, 18 Mar 2018 05:51:53 -0700 (PDT) Received: from localhost (165084180235.ctinets.com. [165.84.180.235]) by smtp.gmail.com with ESMTPSA id t85sm24904578pfg.159.2018.03.18.05.51.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 18 Mar 2018 05:51:52 -0700 (PDT) Date: Sun, 18 Mar 2018 07:51:50 -0500 From: Rob Herring To: Palmer Dabbelt Cc: frowand.list@gmail.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Michael J Clark , Trung Tran , Moritz Fischer Subject: Re: [PATCH] of: Respect CONFIG_CMDLINE{,_EXTENED,_FORCE) with no chosen node Message-ID: <20180318125150.3i54r7i5edefbhfq@rob-hp-laptop> References: <20180314163105.8638-1-palmer@sifive.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180314163105.8638-1-palmer@sifive.com> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 14, 2018 at 09:31:05AM -0700, Palmer Dabbelt wrote: > Systems that boot without a chosen node in the device tree should still > respect the command lines that are built into the kernel. This patch > avoids bailing out of the command line argument parsing code when there > is no chosen node in the device tree. This is necessary to boot > straight to a root file system (ie, without an initramfs) > > The intent here is that the only functional change is to copy > CONFIG_CMDLINE into data if both of them are valid (ie, CONFIG_CMDLINE > is defined and data is non-null) on systems where there is no chosen > device tree node. I don't actually know what the return values do so I > just preserved them. > > Thanks to Trung and Moritz for finding the bug during our ELC hackathon > (and providing the first fix), and Michal for suggesting this fix (which > is cleaner than what I was doing). I've given this very minimal > testing: it fixes the RISC-V bug (in conjunction with a patch to move > from COMMANDLINE_OVERRIDE to COMMANDLINE_FORCE), still works on systems > with and without the chosen node, and builds on ARM64. > > CC: Michael J Clark > CC: Trung Tran > CC: Moritz Fischer > Signed-off-by: Palmer Dabbelt > --- > drivers/of/fdt.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c > index 84aa9d676375..60241b1cb024 100644 > --- a/drivers/of/fdt.c > +++ b/drivers/of/fdt.c > @@ -1084,9 +1084,12 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, > > pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname); > > - if (depth != 1 || !data || > + if (!data) > + goto no_data; Just "return 0" here. > + > + if (depth != 1 || > (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0)) > - return 0; > + goto no_chosen; > > early_init_dt_check_for_initrd(node); > > @@ -1117,6 +1120,13 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, > > /* break now */ > return 1; > + > +no_chosen: > +#ifdef CONFIG_CMDLINE > + strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE); Best case, this is going to needlessly copy the string on every single node that is not /chosen. Worst case, I think this changes behavior. For example, first you copy CONFIG_CMDLINE into data, then on a later iteration, you strlcat CONFIG_CMDLINE into data if CONFIG_CMDLINE_EXTEND is enable. There could also be some unintended behavior if data has a string to start with. I'd really like to see this function re-written to just find the /chosen node and then handle each property one by one. The iterating approach is silly. I assume it predates libfdt and we didn't have nice functions to find nodes by path (or any other way). I'm working on a patch to re-structure this function. Will send it out in the next day. > +#endif > +no_data: > + return 0; > } > > #ifdef CONFIG_HAVE_MEMBLOCK > -- > 2.16.1 >