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 03/10] dtc: Move the /delete-node/ handling out of the grammar
Date: Wed, 25 Nov 2026 11:48:00 +1100 [thread overview]
Message-ID: <awYwOnMy1Y3OLLsF@gractus.seuss> (raw)
In-Reply-To: <20261116235813.935070-4-sjg@chromium.org>
[-- Attachment #1: Type: text/plain, Size: 3211 bytes --]
On Mon, Nov 16, 2026 at 04:57:57PM -0700, Simon Glass wrote:
> The grammar actions merge each top-level fragment of a dts file into the
> tree as it is parsed, so the merge logic is spread over the rules for
> each kind of fragment. This makes it hard to follow and to change.
>
> As a first step towards moving this logic into livetree.c, move the
> action for a top-level /delete-node/ into a new merge_delete_node(),
> passing it a struct fragment for the reference.
>
> The output does not change.
>
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Simon Glass <sjg@chromium.org>
Apart from the name change suggested earlier:
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>
> Changes in v4:
> - Free the fragment after merging it
>
> Changes in v2:
> - Check the fragment type with assert()
> - Return true on success from merge_delete_node()
> - Use dt_ref instead of fragment_ref
>
> dtc-parser.y | 12 +++++-------
> dtc.h | 1 +
> livetree.c | 20 ++++++++++++++++++++
> 3 files changed, 26 insertions(+), 7 deletions(-)
>
> diff --git a/dtc-parser.y b/dtc-parser.y
> index 45a699a..6bf96a7 100644
> --- a/dtc-parser.y
> +++ b/dtc-parser.y
> @@ -239,14 +239,12 @@ devicetree:
> }
> | devicetree DT_DEL_NODE dt_ref ';'
> {
> - struct node *target = get_node_by_ref($1, $3);
> -
> - if (target)
> - delete_node(target);
> - else
> - ERROR(&@3, "Label or path %s not found", $3);
> -
> + struct fragment *f;
>
> + f = build_fragment_delete_node($3, &@3);
> + if (!merge_delete_node($1, f))
> + treesource_error = true;
> + free_fragment(f);
> $$ = $1;
> }
> | devicetree DT_OMIT_NO_REF dt_ref ';'
> diff --git a/dtc.h b/dtc.h
> index ac18616..41ba438 100644
> --- a/dtc.h
> +++ b/dtc.h
> @@ -351,6 +351,7 @@ struct fragment *build_fragment_delete_node(char *ref,
> struct fragment *build_fragment_omit_if_no_ref(char *ref,
> struct srcpos *ref_srcpos);
> void free_fragment(struct fragment *f);
> +bool merge_delete_node(struct node *dt, struct fragment *f);
>
> struct dt_info {
> unsigned int dtsflags;
> diff --git a/livetree.c b/livetree.c
> index 4231c64..ce47fe2 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -534,6 +534,26 @@ struct dt_info *build_dt_info(unsigned int dtsflags,
> return dti;
> }
>
> +/*
> + * Delete the node which a /delete-node/ fragment refers to
> + *
> + * Returns true on success, false on an error, which has been reported.
> + */
> +bool merge_delete_node(struct node *dt, struct fragment *f)
> +{
> + struct node *target = get_node_by_ref(dt, f->ref);
> +
> + assert(f->type == FRAGMENT_DELETE_NODE);
> + if (!target) {
> + srcpos_error(f->ref_srcpos, "Error",
> + "Label or path %s not found", f->ref);
> + return false;
> + }
> + delete_node(target);
> +
> + return true;
> +}
> +
> /*
> * Tree accessor functions
> */
> --
> 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 1:00 UTC|newest]
Thread overview: 34+ 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-26 18:06 ` Simon Glass
2026-11-26 18:40 ` Simon Glass
2026-11-27 2:30 ` 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-26 18:03 ` Simon Glass
2026-11-26 18:34 ` Simon Glass
2026-11-26 20:36 ` Herve Codina
2026-11-27 2:29 ` David Gibson
2026-11-27 3:08 ` Herve Codina
2026-11-27 2:27 ` 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 [this message]
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
2026-11-26 18:33 ` Simon Glass
2026-11-27 2:26 ` David Gibson
2026-11-16 23:58 ` [PATCH v4 10/10] dtc: Move first-reference " Simon Glass
2026-11-25 6:24 ` David Gibson
2026-11-26 18:07 ` 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=awYwOnMy1Y3OLLsF@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.