LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Rob Herring <robh@kernel.org>
To: Palmer Dabbelt <palmer@sifive.com>
Cc: frowand.list@gmail.com, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, Michael J Clark <mjc@sifive.com>,
	Trung Tran <trung.tran@ettus.com>,
	Moritz Fischer <mdf@kernel.org>
Subject: Re: [PATCH] of: Respect CONFIG_CMDLINE{,_EXTENED,_FORCE) with no chosen node
Date: Sun, 18 Mar 2018 07:51:50 -0500	[thread overview]
Message-ID: <20180318125150.3i54r7i5edefbhfq@rob-hp-laptop> (raw)
In-Reply-To: <20180314163105.8638-1-palmer@sifive.com>

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 <mjc@sifive.com>
> CC: Trung Tran <trung.tran@ettus.com>
> CC: Moritz Fischer <mdf@kernel.org>
> Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
> ---
>  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
> 

  reply	other threads:[~2018-03-18 12:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-14 16:31 Palmer Dabbelt
2018-03-18 12:51 ` Rob Herring [this message]
2018-03-18 21:42   ` Michael Clark
2018-03-21  1:12   ` Palmer Dabbelt

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=20180318125150.3i54r7i5edefbhfq@rob-hp-laptop \
    --to=robh@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mdf@kernel.org \
    --cc=mjc@sifive.com \
    --cc=palmer@sifive.com \
    --cc=trung.tran@ettus.com \
    --subject='Re: [PATCH] of: Respect CONFIG_CMDLINE{,_EXTENED,_FORCE) with no chosen node' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).