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 v4 09/10] dtc: Move labelled-reference handling out of the grammar
Date: Wed, 25 Nov 2026 17:21:52 +1100 [thread overview]
Message-ID: <awZ-fxjHSD-ITpug@gractus.seuss> (raw)
In-Reply-To: <20261116235813.935070-10-sjg@chromium.org>
[-- Attachment #1: Type: text/plain, Size: 4866 bytes --]
On Mon, Nov 16, 2026 at 04:58:03PM -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 merge_ref(), passing it a struct fragment with the label.
>
> The output does not change. In a plugin, the error for a label-relative
> reference now gives the position of the reference rather than the label,
> since the problem is with the reference. Update the
> merge-labelled-relative.dts test to match.
>
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v4:
> - Explain why a fragment which adds a label does not go in an overlay
> - Free the fragment after merging it
> - Report the label-relative error at the reference, not the label
>
> Changes in v2:
> - Combine merge_labelled_ref() into merge_ref()
> - Use dt_ref instead of fragment_ref
>
> dtc-parser.y | 14 +++++---------
> livetree.c | 11 ++++++++---
> tests/run_tests.sh | 2 +-
> 3 files changed, 14 insertions(+), 13 deletions(-)
>
> diff --git a/dtc-parser.y b/dtc-parser.y
> index c85b77d..6f7ef24 100644
> --- a/dtc-parser.y
> +++ b/dtc-parser.y
> @@ -180,16 +180,12 @@ devicetree:
> }
> | devicetree DT_LABEL dt_ref nodedef
> {
> - 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);
> + struct fragment *f;
>
> - if (target) {
> - add_label(&target->labels, $2);
> - merge_nodes(target, $4);
> - } else
> - ERROR(&@3, "Label or path %s not found", $3);
> + f = build_fragment_ref($2, $3, &@3, $4);
> + if (!merge_ref($1, f, $<flags>-1 & DTSF_PLUGIN))
> + treesource_error = true;
> + free_fragment(f);
> $$ = $1;
> }
> | devicetree dt_ref nodedef
> diff --git a/livetree.c b/livetree.c
> index 290467f..cf6849a 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -541,10 +541,13 @@ bool is_ref_relative(const char *ref)
> }
>
> /*
> - * Merge a fragment which refers to a label or path into the node it refers to.
> + * 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.
> *
> * In a plugin, a path always refers to the base tree and a label may do so, if
> - * it is not found. In both cases, the fragment becomes an overlay fragment.
> + * it is not found. In both cases, the fragment becomes an overlay fragment,
> + * unless it adds a label, since dtc cannot put a label on the target of an
> + * overlay fragment.
This doesn't seem quite right. It looks like we ignore the label in
that case, whereas we should throw an error, since we can't create a
dtbo which does what was requested.
> *
> * Returns true on success, false on an error, which has been reported.
> */
> @@ -561,7 +564,7 @@ bool merge_ref(struct node *dt, struct fragment *f, bool plugin)
> f->ref);
> ok = false;
> }
> - if (f->ref[0] == '/' || !target) {
> + if (!f->label && (f->ref[0] == '/' || !target)) {
> /* Add a fragment@N node for the reference */
> add_orphan_node(dt, f->node, f->ref);
> return ok;
> @@ -573,6 +576,8 @@ bool merge_ref(struct node *dt, struct fragment *f, bool plugin)
> "Label or path %s not found", f->ref);
> return false;
> }
> + if (f->label)
> + add_label(&target->labels, f->label);
> merge_nodes(target, f->node);
>
> return ok;
> diff --git a/tests/run_tests.sh b/tests/run_tests.sh
> index 7f9a24a..62732a4 100755
> --- a/tests/run_tests.sh
> +++ b/tests/run_tests.sh
> @@ -781,7 +781,7 @@ dtc_tests () {
> $DTC -I dts -O dtb -o /dev/null "$SRCDIR/merge-first-ref.dts"
> run_wrap_error_msg_test "merge-first-ref-relative.dts:5.15-7.3 Label-relative reference label/node not supported in plugin" \
> $DTC -I dts -O dtb -o /dev/null "$SRCDIR/merge-first-ref-relative.dts"
> - run_wrap_error_msg_test "merge-labelled-relative.dts:8.1-10 Label-relative reference baselabel/subnode not supported in plugin" \
> + run_wrap_error_msg_test "merge-labelled-relative.dts:8.11-31 Label-relative reference baselabel/subnode not supported in plugin" \
> $DTC -I dts -O dtb -o /dev/null "$SRCDIR/merge-labelled-relative.dts"
> run_wrap_error_msg_test "merge-path-relative.dts:8.1-18 Label-relative reference baselabel/node not supported in plugin" \
> $DTC -I dts -O dtb -o /dev/null "$SRCDIR/merge-path-relative.dts"
> --
> 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-25 6:40 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 23:57 [PATCH v4 00/10] dtc: Move the merging of fragments out of the grammar Simon Glass
2026-11-16 23:57 ` [PATCH v4 01/10] tests: Check how the fragments of a dts file are merged Simon Glass
2026-11-25 0:34 ` David Gibson
2026-11-25 6:42 ` David Gibson
2026-11-16 23:57 ` [PATCH v4 02/10] dtc: Add a struct for the top-level fragments of a dts file Simon Glass
2026-11-25 0:44 ` David Gibson
2026-11-16 23:57 ` [PATCH v4 03/10] dtc: Move the /delete-node/ handling out of the grammar Simon Glass
2026-11-25 0:48 ` David Gibson
2026-11-16 23:57 ` [PATCH v4 04/10] dtc: Move the /omit-if-no-ref/ " Simon Glass
2026-11-25 1:15 ` David Gibson
2026-11-16 23:57 ` [PATCH v4 05/10] dtc: Move is_ref_relative() to livetree.c Simon Glass
2026-11-25 1:16 ` David Gibson
2026-11-16 23:58 ` [PATCH v4 06/10] dtc: Move label-reference handling out of the grammar Simon Glass
2026-11-25 6:12 ` David Gibson
2026-11-16 23:58 ` [PATCH v4 07/10] dtc: Merge &{label} in a plugin as with &label Simon Glass
2026-11-25 6:16 ` David Gibson
2026-11-16 23:58 ` [PATCH v4 08/10] dtc: Move path-reference handling out of the grammar Simon Glass
2026-11-25 6:18 ` David Gibson
2026-11-16 23:58 ` [PATCH v4 09/10] dtc: Move labelled-reference " Simon Glass
2026-11-25 6:21 ` David Gibson [this message]
2026-11-16 23:58 ` [PATCH v4 10/10] dtc: Move first-reference " Simon Glass
2026-11-25 6:24 ` 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=awZ-fxjHSD-ITpug@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox