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>,
	Herve Codina <herve.codina@bootlin.com>
Subject: Re: [PATCH v3 11/18] dtc: Move first-reference handling out of the grammar
Date: Fri, 13 Nov 2026 15:19:27 +1100	[thread overview]
Message-ID: <avaPzn8RJMGiOWZA@gractus.seuss> (raw)
In-Reply-To: <20261106195159.2623314-12-sjg@chromium.org>

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

On Fri, Nov 06, 2026 at 12:51:38PM -0700, Simon Glass wrote:
> In a plugin, the first top-level fragment can refer to a label or path
> instead of being the root node. The grammar action for this holds its
> merge logic, which makes an overlay fragment in a new tree.
> 
> Move it into a new merge_first_ref(), passing it a struct fragment for
> the reference and node. This is the last user of is_ref_relative() in
> the grammar, so make that function static.
> 
> The output does not change.
> 
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Simon Glass <sjg@chromium.org>

I hope the first fragment will be less special cased than this in the
end, but this looks fine as an interim step.

> ---
> 
> (no changes since v2)
> 
> Changes in v2:
> - Use dt_ref instead of fragment_ref
> - Return true on success from merge_first_ref()
> 
>  dtc-parser.y | 13 +++++--------
>  dtc.h        |  2 +-
>  livetree.c   | 30 +++++++++++++++++++++++++++++-
>  3 files changed, 35 insertions(+), 10 deletions(-)
> 
> diff --git a/dtc-parser.y b/dtc-parser.y
> index 8d505a1..abeee0d 100644
> --- a/dtc-parser.y
> +++ b/dtc-parser.y
> @@ -163,19 +163,16 @@ devicetree:
>  		}
>  	| dt_ref nodedef
>  		{
> +			struct fragment *f;
> +
> +			f = build_fragment_ref(NULL, NULL, $1, &@1, $2);
>  			/*
>  			 * We rely on the rule being always:
>  			 *   versioninfo plugindecl memreserves devicetree
>  			 * so $-1 is what we want (plugindecl)
>  			 */
> -			if (!($<flags>-1 & DTSF_PLUGIN))
> -				ERROR(&@2, "Label or path %s not found", $1);
> -			else if (is_ref_relative($1))
> -				ERROR(&@2, "Label-relative reference %s not supported in plugin", $1);
> -			$$ = add_orphan_node(
> -					name_node(build_node(NULL, NULL, NULL),
> -						  ""),
> -					$2, $1);
> +			if (!merge_first_ref(&$$, f, $<flags>-1 & DTSF_PLUGIN))
> +				treesource_error = true;
>  		}
>  	| devicetree DT_LABEL dt_ref nodedef
>  		{
> diff --git a/dtc.h b/dtc.h
> index 9b4389b..1befd5c 100644
> --- a/dtc.h
> +++ b/dtc.h
> @@ -372,7 +372,7 @@ struct fragment *build_fragment_omit_if_no_ref(char *ref,
>  					       struct srcpos *ref_srcpos);
>  struct fragment *append_fragment(struct fragment *list, struct fragment *new);
>  void free_fragment(struct fragment *f);
> -bool is_ref_relative(const char *ref);
> +bool merge_first_ref(struct node **dtp, struct fragment *f, bool plugin);
>  bool merge_ref(struct node *dt, struct fragment *f, bool plugin);
>  bool merge_delete_node(struct node *dt, struct fragment *f);
>  bool merge_omit_if_no_ref(struct node *dt, struct fragment *f);
> diff --git a/livetree.c b/livetree.c
> index 7ab9437..26d39df 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -568,11 +568,39 @@ struct dt_info *build_dt_info(unsigned int dtsflags,
>  }
>  
>  /* Check whether a reference is relative to a label, e.g. &{label/node} */
> -bool is_ref_relative(const char *ref)
> +static bool is_ref_relative(const char *ref)
>  {
>  	return ref[0] != '/' && strchr(&ref[1], '/');
>  }
>  
> +/*
> + * Make the tree at *dtp from a first fragment which refers to a label or path,
> + * rather than being the root node. This is only valid in a plugin, where the
> + * fragment becomes an overlay fragment.
> + *
> + * Returns true on success, false on an error, which has been reported.
> + */
> +bool merge_first_ref(struct node **dtp, struct fragment *f, bool plugin)
> +{
> +	bool ok = true;
> +
> +	if (!plugin) {
> +		srcpos_error(f->node->srcpos, "Error",
> +			     "Label or path %s not found", f->ref);
> +		ok = false;
> +	} else if (is_ref_relative(f->ref)) {
> +		srcpos_error(f->node->srcpos, "Error",
> +			     "Label-relative reference %s not supported in plugin",
> +			     f->ref);
> +		ok = false;
> +	}
> +	/* Make a new, empty tree with a fragment@N node for the reference */
> +	*dtp = add_orphan_node(name_node(build_node(NULL, NULL, NULL), ""),
> +			       f->node, f->ref);
> +
> +	return ok;
> +}
> +
>  /*
>   * Merge a fragment which refers to a label or path into the node it refers to,
>   * adding any label in the fragment to that node.
> -- 
> 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-11-13  4:19 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 19:51 [PATCH v3 00/18] dtc: Merge the fragments of a dts file after parsing Simon Glass
2026-11-06 19:51 ` [PATCH v3 01/18] tests: Check how the fragments of a dts file are merged Simon Glass
2026-11-13  3:20   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 02/18] srcpos: Allow srcpos_string() to accept NULL Simon Glass
2026-11-11  4:56   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 03/18] dtc: Add a struct for the top-level fragments of a dts file Simon Glass
2026-11-13  3:46   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 04/18] dtc: Move the /delete-node/ handling out of the grammar Simon Glass
2026-11-13  3:49   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 05/18] dtc: Move the /omit-if-no-ref/ " Simon Glass
2026-11-13  3:50   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 06/18] dtc: Move is_ref_relative() to livetree.c Simon Glass
2026-11-13  3:55   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 07/18] dtc: Move label-reference handling out of the grammar Simon Glass
2026-11-13  3:58   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 08/18] dtc: Merge &{label} in a plugin as with &label Simon Glass
2026-11-13  4:01   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 09/18] dtc: Move path-reference handling out of the grammar Simon Glass
2026-11-13  4:09   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 10/18] dtc: Move labelled-reference " Simon Glass
2026-11-13  4:13   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 11/18] dtc: Move first-reference " Simon Glass
2026-11-13  4:19   ` David Gibson [this message]
2026-11-06 19:51 ` [PATCH v3 12/18] dtc: Add merge_fragment() to merge any fragment Simon Glass
2026-11-13  4:24   ` David Gibson
2026-11-06 19:51 ` [PATCH v3 13/18] dtc: Add helpers for the errors when merging a fragment Simon Glass
2026-11-06 19:51 ` [PATCH v3 14/18] dtc: Merge the fragments of a dts file after parsing Simon Glass
2026-11-06 19:51 ` [PATCH v3 15/18] dtc: Merge the fragments of a dts file in main() Simon Glass
2026-11-06 19:51 ` [PATCH v3 16/18] dtc: Add the overlay fragments from merge_fragments() Simon Glass
2026-11-06 19:51 ` [PATCH v3 17/18] tests: Check references to a generated overlay fragment Simon Glass
2026-11-06 19:51 ` [PATCH v3 18/18] dtc: Add the overlay fragments after merging a plugin Simon Glass

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=avaPzn8RJMGiOWZA@gractus.seuss \
    --to=david@gibson.dropbear.id.au \
    --cc=devicetree-compiler@vger.kernel.org \
    --cc=herve.codina@bootlin.com \
    --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.