[RFC PATCH 40/77] dtc: Introduce dti_get_node_by_path()

Herve Codina posted 77 patches 3 weeks, 6 days ago
[RFC PATCH 40/77] dtc: Introduce dti_get_node_by_path()
Posted by Herve Codina 3 weeks, 6 days ago
The future introduction of orphan nodes for addons device-tree will lead
to more than one tree in the addons data. Those trees will be:
  - the classical root tree starting at the root node
  - trees related to orphan nodes

Also, an addon device-tree can have only trees based on orphan nodes. In
other words an addon device-tree is valid without having the classical
'root' tree.

To prepare this change, introduce and use dti_get_node_by_path().

dti_get_node_by_path() retrieves a node by its path like
get_node_by_path() but it works at the struct dt_info level.

It handles the case where a 'root' device-tree is not present and will
handle orphan nodes trees as soon as they will be introduced.

This introduction doesn't lead to any functional changes.

Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
 checks.c   |  2 +-
 dtc.h      |  3 ++-
 livetree.c | 15 ++++++++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/checks.c b/checks.c
index 9744431..b2b1bf7 100644
--- a/checks.c
+++ b/checks.c
@@ -740,7 +740,7 @@ static void check_alias_paths(struct check *c, struct dt_info *dti,
 
 		/* This check does not work for overlays nor addons with external paths */
 		if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON)) &&
-		    (!prop->val.val || !get_node_by_path(dti->dt, prop->val.val))) {
+		    (!prop->val.val || !dti_get_node_by_path(dti, prop->val.val))) {
 			FAIL_PROP(c, dti, node, prop, "aliases property is not a valid node (%s)",
 				  prop->val.val);
 			continue;
diff --git a/dtc.h b/dtc.h
index 4ebe576..8ba093f 100644
--- a/dtc.h
+++ b/dtc.h
@@ -323,7 +323,6 @@ struct property *get_property_by_label(struct node *tree, const char *label,
 struct marker *get_marker_label(struct node *tree, const char *label,
 				struct node **node, struct property **prop);
 struct node *get_subnode(struct node *node, const char *nodename);
-struct node *get_node_by_path(struct node *tree, const char *path);
 struct node *get_node_by_label(struct node *tree, const char *label);
 struct node *get_node_by_phandle(struct node *tree, cell_t phandle);
 struct node *get_node_by_ref(struct node *tree, const char *ref);
@@ -357,6 +356,8 @@ struct dt_info {
 	const char *outname;		/* filename being written to, "-" for stdout */
 };
 
+struct node *dti_get_node_by_path(struct dt_info *dti, const char *path);
+
 /* DTS version flags definitions */
 #define DTSF_V1		0x0001	/* /dts-v1/ */
 #define DTSF_PLUGIN	0x0002	/* /plugin/ */
diff --git a/livetree.c b/livetree.c
index 285f6e1..23ba957 100644
--- a/livetree.c
+++ b/livetree.c
@@ -659,7 +659,7 @@ struct node *get_subnode(struct node *node, const char *nodename)
 	return NULL;
 }
 
-struct node *get_node_by_path(struct node *tree, const char *path)
+static struct node *get_node_by_path(struct node *tree, const char *path)
 {
 	const char *p;
 	struct node *child;
@@ -785,6 +785,19 @@ struct node *get_node_by_ref(struct node *tree, const char *ref)
 	return target;
 }
 
+struct node *dti_get_node_by_path(struct dt_info *dti, const char *path)
+{
+	struct node *node;
+
+	if (dti->dt) {
+		node = get_node_by_path(dti->dt, path);
+		if (node)
+			return node;
+	}
+
+	return NULL;
+}
+
 static void add_phandle_property(struct node *node,
 				 const char *name, int format)
 {
-- 
2.52.0
Re: [RFC PATCH 40/77] dtc: Introduce dti_get_node_by_path()
Posted by David Gibson 3 weeks, 3 days ago
On Mon, Jan 12, 2026 at 03:19:30PM +0100, Herve Codina wrote:
> The future introduction of orphan nodes for addons device-tree will lead
> to more than one tree in the addons data. Those trees will be:
>   - the classical root tree starting at the root node
>   - trees related to orphan nodes

This doesn't make sense to me.  The new function still just takes a
single path, nothing to specify which tree that path is looked up in.

You can probably guarantee that labels and phandles are unique across
all the trees.  Not paths, though.

> 
> Also, an addon device-tree can have only trees based on orphan nodes. In
> other words an addon device-tree is valid without having the classical
> 'root' tree.
> 
> To prepare this change, introduce and use dti_get_node_by_path().
> 
> dti_get_node_by_path() retrieves a node by its path like
> get_node_by_path() but it works at the struct dt_info level.
> 
> It handles the case where a 'root' device-tree is not present and will
> handle orphan nodes trees as soon as they will be introduced.
> 
> This introduction doesn't lead to any functional changes.
> 
> Signed-off-by: Herve Codina <herve.codina@bootlin.com>
> ---
>  checks.c   |  2 +-
>  dtc.h      |  3 ++-
>  livetree.c | 15 ++++++++++++++-
>  3 files changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/checks.c b/checks.c
> index 9744431..b2b1bf7 100644
> --- a/checks.c
> +++ b/checks.c
> @@ -740,7 +740,7 @@ static void check_alias_paths(struct check *c, struct dt_info *dti,
>  
>  		/* This check does not work for overlays nor addons with external paths */
>  		if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON)) &&
> -		    (!prop->val.val || !get_node_by_path(dti->dt, prop->val.val))) {
> +		    (!prop->val.val || !dti_get_node_by_path(dti, prop->val.val))) {
>  			FAIL_PROP(c, dti, node, prop, "aliases property is not a valid node (%s)",
>  				  prop->val.val);
>  			continue;
> diff --git a/dtc.h b/dtc.h
> index 4ebe576..8ba093f 100644
> --- a/dtc.h
> +++ b/dtc.h
> @@ -323,7 +323,6 @@ struct property *get_property_by_label(struct node *tree, const char *label,
>  struct marker *get_marker_label(struct node *tree, const char *label,
>  				struct node **node, struct property **prop);
>  struct node *get_subnode(struct node *node, const char *nodename);
> -struct node *get_node_by_path(struct node *tree, const char *path);
>  struct node *get_node_by_label(struct node *tree, const char *label);
>  struct node *get_node_by_phandle(struct node *tree, cell_t phandle);
>  struct node *get_node_by_ref(struct node *tree, const char *ref);
> @@ -357,6 +356,8 @@ struct dt_info {
>  	const char *outname;		/* filename being written to, "-" for stdout */
>  };
>  
> +struct node *dti_get_node_by_path(struct dt_info *dti, const char *path);
> +
>  /* DTS version flags definitions */
>  #define DTSF_V1		0x0001	/* /dts-v1/ */
>  #define DTSF_PLUGIN	0x0002	/* /plugin/ */
> diff --git a/livetree.c b/livetree.c
> index 285f6e1..23ba957 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -659,7 +659,7 @@ struct node *get_subnode(struct node *node, const char *nodename)
>  	return NULL;
>  }
>  
> -struct node *get_node_by_path(struct node *tree, const char *path)
> +static struct node *get_node_by_path(struct node *tree, const char *path)
>  {
>  	const char *p;
>  	struct node *child;
> @@ -785,6 +785,19 @@ struct node *get_node_by_ref(struct node *tree, const char *ref)
>  	return target;
>  }
>  
> +struct node *dti_get_node_by_path(struct dt_info *dti, const char *path)
> +{
> +	struct node *node;
> +
> +	if (dti->dt) {
> +		node = get_node_by_path(dti->dt, path);
> +		if (node)
> +			return node;
> +	}
> +
> +	return NULL;
> +}
> +
>  static void add_phandle_property(struct node *node,
>  				 const char *name, int format)
>  {
> -- 
> 2.52.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
Re: [RFC PATCH 40/77] dtc: Introduce dti_get_node_by_path()
Posted by Herve Codina 2 weeks, 6 days ago
Hi David,

On Thu, 15 Jan 2026 17:47:29 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Mon, Jan 12, 2026 at 03:19:30PM +0100, Herve Codina wrote:
> > The future introduction of orphan nodes for addons device-tree will lead
> > to more than one tree in the addons data. Those trees will be:
> >   - the classical root tree starting at the root node
> >   - trees related to orphan nodes  
> 
> This doesn't make sense to me.  The new function still just takes a
> single path, nothing to specify which tree that path is looked up in.
> 
> You can probably guarantee that labels and phandles are unique across
> all the trees.  Not paths, though.
> 

Paths can be unique across all trees. The tree needs to be indicated in the
path. Starting by '/' is the root tree.

For orphans, I proposed "$<orphan_name>/<path>" in patch 64 introducing
references by path for orphan nodes and so, for orphan trees.

Best regards,
Hervé
Re: [RFC PATCH 40/77] dtc: Introduce dti_get_node_by_path()
Posted by David Gibson 1 week, 4 days ago
On Mon, Jan 19, 2026 at 04:52:44PM +0100, Herve Codina wrote:
> Hi David,
> 
> On Thu, 15 Jan 2026 17:47:29 +1100
> David Gibson <david@gibson.dropbear.id.au> wrote:
> 
> > On Mon, Jan 12, 2026 at 03:19:30PM +0100, Herve Codina wrote:
> > > The future introduction of orphan nodes for addons device-tree will lead
> > > to more than one tree in the addons data. Those trees will be:
> > >   - the classical root tree starting at the root node
> > >   - trees related to orphan nodes  
> > 
> > This doesn't make sense to me.  The new function still just takes a
> > single path, nothing to specify which tree that path is looked up in.
> > 
> > You can probably guarantee that labels and phandles are unique across
> > all the trees.  Not paths, though.
> > 
> 
> Paths can be unique across all trees. The tree needs to be indicated in the
> path. Starting by '/' is the root tree.

Oh, ok.  That wasn't clear from this patch, and I must have missed it
in my cursory look at the later patches.  I had the mistaken
impression this just looked for the same path in each orphan tree.

> For orphans, I proposed "$<orphan_name>/<path>" in patch 64 introducing
> references by path for orphan nodes and so, for orphan trees.
> 
> Best regards,
> Hervé
> 

-- 
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