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 08/13] dtc: Move labelled-reference handling out of the grammar
Date: Tue, 3 Nov 2026 18:29:31 +1100 [thread overview]
Message-ID: <aumNU6YhSTKzkmGi@gractus.seuss> (raw)
In-Reply-To: <20261101163721.2458982-9-sjg@chromium.org>
[-- Attachment #1: Type: text/plain, Size: 3901 bytes --]
On Sun, Nov 01, 2026 at 09:37:02AM -0700, Simon Glass wrote:
> The grammar action for a top-level label: &ref { ... } holds its merge
> logic, which adds the label to the node referred to.
>
> Move it into a new merge_labelled_ref(), passing it a struct fragment
> from fragment_ref, with the label and node added.
>
> The output does not change.
>
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> dtc-parser.y | 18 +++++++-----------
> dtc.h | 2 ++
> livetree.c | 28 ++++++++++++++++++++++++++++
> 3 files changed, 37 insertions(+), 11 deletions(-)
>
> diff --git a/dtc-parser.y b/dtc-parser.y
> index cca3ce1..0e6c4c2 100644
> --- a/dtc-parser.y
> +++ b/dtc-parser.y
> @@ -190,18 +190,14 @@ devicetree:
> ""),
> $2, $1);
> }
> - | devicetree DT_LABEL dt_ref nodedef
> + | devicetree DT_LABEL fragment_ref nodedef
Usual comments on fragment_ref.
> {
> - struct node *target = get_node_by_ref($1, $3);
> -
> - if (($<flags>-1 & DTSF_PLUGIN) && is_ref_relative($3))
> - ERROR(&@2, "Label-relative reference %s not supported in plugin", $3);
> -
> - if (target) {
> - add_label(&target->labels, $2);
> - merge_nodes(target, $4);
> - } else
> - ERROR(&@3, "Label or path %s not found", $3);
> + $3->label = $2;
> + $3->label_srcpos = srcpos_copy(&@2);
> + $3->node = $4;
> + if (merge_labelled_ref($1, $3,
> + $<flags>-1 & DTSF_PLUGIN))
> + treesource_error = true;
> $$ = $1;
> }
> | devicetree DT_PATH_REF nodedef
> diff --git a/dtc.h b/dtc.h
> index 5af1d1f..75b1c0f 100644
> --- a/dtc.h
> +++ b/dtc.h
> @@ -369,6 +369,8 @@ struct fragment *build_fragment_ref(char *ref, bool path_ref,
> 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_labelled_ref(struct node *dt, struct fragment *f,
> + bool plugin);
> bool merge_path_ref(struct node *dt, struct fragment *f, bool plugin);
> bool merge_label_ref(struct node *dt, struct fragment *f, bool plugin);
> bool merge_delete_node(struct node *dt, struct fragment *f);
> diff --git a/livetree.c b/livetree.c
> index b0362e4..76474cd 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -548,6 +548,34 @@ bool is_ref_relative(const char *ref)
> return ref[0] != '/' && strchr(&ref[1], '/');
> }
>
> +/*
> + * Merge a fragment of the form 'label: &ref { ... }' into the node which ref
> + * refers to, adding the label to that node
> + *
> + * Returns true if there is an error, which has been reported.
> + */
> +bool merge_labelled_ref(struct node *dt, struct fragment *f, bool plugin)
This again seems like the fragment itself contains the information to
do the right thing for path/label or labelled fragments, rather than
having separate functions for each case.
> +{
> + struct node *target = get_node_by_ref(dt, f->ref);
> + bool error = false;
> +
> + if (plugin && is_ref_relative(f->ref)) {
> + srcpos_error(f->label_srcpos, "Error",
> + "Label-relative reference %s not supported in plugin",
> + f->ref);
> + error = true;
> + }
> + if (!target) {
> + srcpos_error(f->ref_srcpos, "Error",
> + "Label or path %s not found", f->ref);
> + return true;
> + }
> + add_label(&target->labels, f->label);
> + merge_nodes(target, f->node);
> +
> + return error;
> +}
> +
> /*
> * Merge a fragment which refers to a path into the node at that path. In a
> * plugin, the fragment becomes an overlay fragment instead.
> --
> 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 --]
next prev parent reply other threads:[~2026-11-03 7:34 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-01 16:36 [PATCH 00/13] dtc: Merge the fragments of a dts file after parsing Simon Glass
2026-11-01 16:36 ` [PATCH 01/13] tests: Check each error when merging a dts file Simon Glass
2026-11-02 6:32 ` David Gibson
2026-11-04 15:15 ` Simon Glass
2026-11-01 16:36 ` [PATCH 02/13] dtc: Add a list for the top-level fragments of " Simon Glass
2026-11-02 9:49 ` David Gibson
2026-11-03 17:56 ` Herve Codina
2026-11-04 6:32 ` David Gibson
2026-11-04 8:29 ` Herve Codina
2026-11-04 9:34 ` David Gibson
2026-11-04 15:18 ` Simon Glass
2026-11-03 17:07 ` Herve Codina
2026-11-04 6:28 ` David Gibson
2026-11-01 16:36 ` [PATCH 03/13] dtc: Move the /delete-node/ handling out of the grammar Simon Glass
2026-11-02 9:55 ` David Gibson
2026-11-04 15:15 ` Simon Glass
2026-11-01 16:36 ` [PATCH 04/13] dtc: Move the /omit-if-no-ref/ " Simon Glass
2026-11-02 10:03 ` David Gibson
2026-11-01 16:36 ` [PATCH 05/13] dtc: Move is_ref_relative() to livetree.c Simon Glass
2026-11-02 10:04 ` David Gibson
2026-11-01 16:37 ` [PATCH 06/13] dtc: Move label-reference handling out of the grammar Simon Glass
2026-11-03 7:25 ` David Gibson
2026-11-01 16:37 ` [PATCH 07/13] dtc: Move path-reference " Simon Glass
2026-11-03 7:27 ` David Gibson
2026-11-04 15:16 ` Simon Glass
2026-11-01 16:37 ` [PATCH 08/13] dtc: Move labelled-reference " Simon Glass
2026-11-03 7:29 ` David Gibson [this message]
2026-11-04 15:16 ` Simon Glass
2026-11-01 16:37 ` [PATCH 09/13] dtc: Move first-reference " Simon Glass
2026-11-01 16:37 ` [PATCH 10/13] dtc: Add merge_fragment() to merge any fragment Simon Glass
2026-11-01 16:37 ` [PATCH 11/13] dtc: Add helpers for the errors when merging a fragment Simon Glass
2026-11-03 17:23 ` Herve Codina
2026-11-04 6:49 ` David Gibson
2026-11-04 8:55 ` Herve Codina
2026-11-01 16:37 ` [PATCH 12/13] dtc: Merge the fragments of a dts file after parsing Simon Glass
2026-11-03 17:07 ` Herve Codina
2026-11-04 6:50 ` David Gibson
2026-11-04 15:18 ` Simon Glass
2026-11-01 16:37 ` [PATCH 13/13] dtc: Merge the fragments of a dts file in main() Simon Glass
2026-11-03 17:08 ` Herve Codina
2026-11-04 6:51 ` David Gibson
2026-11-04 8:40 ` Herve Codina
2026-11-04 9:47 ` David Gibson
2026-11-04 13:23 ` Herve Codina
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=aumNU6YhSTKzkmGi@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.