All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Simon Glass <sjg@chromium.org>
Cc: Devicetree Compiler <devicetree-compiler@vger.kernel.org>
Subject: Re: [PATCH 2/5] fdtput: Follow an alias when creating nodes with -p
Date: Wed, 28 Oct 2026 12:34:12 +1100	[thread overview]
Message-ID: <auFRAPRBaxrX9gYW@gractus.seuss> (raw)
In-Reply-To: <20261027120126.2613353-3-sjg@chromium.org>

[-- Attachment #1: Type: text/plain, Size: 3899 bytes --]

On Tue, Oct 27, 2026 at 06:01:16AM -0600, Simon Glass wrote:
> A node path can start with an alias, such as serial0/sub, but -p does
> not allow for this. It looks up each part of the path from the root, so
> it creates a top-level node named after the alias:
> 
>    $ fdtput -cp test.dtb serial0/sub
> 
> This creates /serial0/sub instead of adding 'sub' to the node which
> serial0 points to, and reports success. When writing a property, the
> stray node is left behind if the alias is the whole path, and fdtput
> fails if the path continues beyond the alias.
> 
> When the path starts with an alias, create any missing nodes below the
> node which the alias points to. Keep the existing behaviour for other
> paths which do not start with '/', which are created from the root.
> 
> Fixes: f807af192828 ("fdtput: Add -p option to create subnodes along entire path")
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
>  fdtput.c           | 18 ++++++++++++++++--
>  tests/run_tests.sh |  7 +++++++
>  2 files changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/fdtput.c b/fdtput.c
> index c139de1..4094015 100644
> --- a/fdtput.c
> +++ b/fdtput.c
> @@ -201,8 +201,9 @@ static int store_key_value(char **blob, const char *node_name,
>  /**
>   * Create paths as needed for all components of a path
>   *
> - * Any components of the path that do not exist are created. Errors are
> - * reported.
> + * Any components of the path that do not exist are created. If the path
> + * starts with an alias, they are created below the node which the alias
> + * points to. Otherwise the path starts at the root. Errors are reported.
>   *
>   * @param blob		FDT blob to write into
>   * @param in_path	Path to process
> @@ -214,6 +215,19 @@ static int create_paths(char **blob, const char *in_path)
>  	const char *sep;
>  	int node, offset = 0;
>  
> +	/* a path which starts with an alias is created below its node */
> +	sep = strchr(path, '/');
> +	if (!sep)
> +		sep = path + strlen(path);
> +	if (sep > path && fdt_get_alias_namelen(*blob, path, sep - path)) {
> +		offset = fdt_path_offset_namelen(*blob, path, sep - path);
> +		if (offset < 0) {
> +			report_error(path, sep - path, offset);
> +			return -1;
> +		}
> +		path = sep;
> +	}
> +

The previous behaviour was certainly buggy, but I don't think this fix
is quite correct.  If 'foo' is *not* an existing alias, then
	fdtput -cp test.dtb foo/bar/baz
Will still create /foo/bar/baz, which is not how dt paths generally
work.

Instead, we should look for an alias if and only if there's no leading
'/'.  If there's no leading '/' but the first segment is not a valid
alias, then we should error out.

>  	/* skip leading '/' */
>  	while (*path == '/')
>  		path++;
> diff --git a/tests/run_tests.sh b/tests/run_tests.sh
> index 842b543..77f0a81 100755
> --- a/tests/run_tests.sh
> +++ b/tests/run_tests.sh
> @@ -970,6 +970,13 @@ fdtput_tests () {
>  	"-ts" "fine wine"
>      run_wrap_test $DTPUT $dtb -p /you/are/drunk/sir/winston slurp -ts twice
>  
> +    # Automatic node creation below an alias
> +    run_wrap_test $DTPUT $dtb -p /aliases second -ts /blackadder/the-second
> +    run_wrap_test $DTPUT $dtb -cp second/carrot
> +    run_fdtput_test "orange" $dtb second/carrot colour -ts "orange"
> +    run_fdtget_test "orange" $dtb /blackadder/the-second/carrot colour
> +    run_wrap_error_test $DTGET $dtb -l /second
> +
>      # Test expansion of the blob when insufficient room for a new node
>      run_wrap_test $DTPUT $dtb -cp "$(cat $text $text)/longish"
>  
> -- 
> 2.43.0
> 
> 

-- 
David Gibson (he or they)	| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you, not the other way
				| around.
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2026-10-28  1:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 12:01 [PATCH 0/5] fdtput: Make it clearer how to create nodes Simon Glass
2026-10-27 12:01 ` [PATCH 1/5] fdtput: Explain " Simon Glass
2026-10-27 12:01 ` [PATCH 2/5] fdtput: Follow an alias when creating nodes with -p Simon Glass
2026-10-28  1:34   ` David Gibson [this message]
2026-10-27 12:01 ` [PATCH 3/5] fdtput: Suggest -p when a node is missing Simon Glass
2026-10-28  1:39   ` David Gibson
2026-10-28  7:39     ` Simon Glass
2026-10-27 12:01 ` [PATCH 4/5] fdtput: Name the property when it cannot be deleted Simon Glass
2026-10-28  1:43   ` David Gibson
2026-10-27 12:01 ` [PATCH 5/5] fdtput: Correct the description of -t in the manual Simon Glass
2026-10-28  1:58 ` [PATCH 0/5] fdtput: Make it clearer how to create nodes David Gibson

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=auFRAPRBaxrX9gYW@gractus.seuss \
    --to=david@gibson.dropbear.id.au \
    --cc=devicetree-compiler@vger.kernel.org \
    --cc=sjg@chromium.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.