[RFC PATCH 46/77] dtc: Introduce dti_get_marker_label()

Herve Codina posted 77 patches 3 weeks, 5 days ago
[RFC PATCH 46/77] dtc: Introduce dti_get_marker_label()
Posted by Herve Codina 3 weeks, 5 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_marker_label().

dti_get_marker_label() retrieves a marker and its related node and
property based on the label value. It behaves in the same way as
get_marker_label() 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   |  5 ++---
 dtc.h      |  4 ++--
 livetree.c | 18 +++++++++++++++++-
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/checks.c b/checks.c
index 75040c0..0a855f9 100644
--- a/checks.c
+++ b/checks.c
@@ -439,7 +439,6 @@ static void check_duplicate_label(struct check *c, struct dt_info *dti,
 				  const char *label, struct node *node,
 				  struct property *prop, struct marker *mark)
 {
-	struct node *dt = dti->dt;
 	struct node *othernode = NULL;
 	struct property *otherprop = NULL;
 	struct marker *othermark = NULL;
@@ -449,8 +448,8 @@ static void check_duplicate_label(struct check *c, struct dt_info *dti,
 	if (!othernode)
 		otherprop = dti_get_property_by_label(dti, label, &othernode);
 	if (!othernode)
-		othermark = get_marker_label(dt, label, &othernode,
-					       &otherprop);
+		othermark = dti_get_marker_label(dti, label, &othernode,
+						 &otherprop);
 
 	if (!othernode)
 		return;
diff --git a/dtc.h b/dtc.h
index 399e7fa..d45a84c 100644
--- a/dtc.h
+++ b/dtc.h
@@ -318,8 +318,6 @@ const char *get_unitname(struct node *node);
 struct property *get_property(struct node *node, const char *propname);
 cell_t propval_cell(struct property *prop);
 cell_t propval_cell_n(struct property *prop, unsigned int n);
-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);
 
 uint32_t guess_boot_cpuid(struct node *tree);
@@ -358,6 +356,8 @@ cell_t dti_get_node_phandle(struct dt_info *dti, struct node *node);
 struct property *dti_get_property_by_label(struct dt_info *dti,
 					   const char *label,
 					   struct node **node);
+struct marker *dti_get_marker_label(struct dt_info *dti, const char *label,
+				    struct node **node, struct property **prop);
 
 /* DTS version flags definitions */
 #define DTSF_V1		0x0001	/* /dts-v1/ */
diff --git a/livetree.c b/livetree.c
index d023075..79f7b55 100644
--- a/livetree.c
+++ b/livetree.c
@@ -620,7 +620,7 @@ static struct property *get_property_by_label(struct node *tree, const char *lab
 	return NULL;
 }
 
-struct marker *get_marker_label(struct node *tree, const char *label,
+static struct marker *get_marker_label(struct node *tree, const char *label,
 				struct node **node, struct property **prop)
 {
 	struct marker *m;
@@ -853,6 +853,22 @@ struct property *dti_get_property_by_label(struct dt_info *dti,
 	return NULL;
 }
 
+struct marker *dti_get_marker_label(struct dt_info *dti, const char *label,
+				    struct node **node, struct property **prop)
+{
+	struct marker *marker;
+
+	if (dti->dt) {
+		marker = get_marker_label(dti->dt, label, node, prop);
+		if (marker)
+			return marker;
+	}
+
+	*prop = NULL;
+	*node = NULL;
+	return NULL;
+}
+
 static void add_phandle_property(struct node *node,
 				 const char *name, int format)
 {
-- 
2.52.0
Re: [RFC PATCH 46/77] dtc: Introduce dti_get_marker_label()
Posted by David Gibson 3 weeks, 3 days ago
On Mon, Jan 12, 2026 at 03:19:36PM +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
> 
> 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_marker_label().
> 
> dti_get_marker_label() retrieves a marker and its related node and
> property based on the label value. It behaves in the same way as
> get_marker_label() 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.

For all of these functions, if the new one is basically replacing the
old one, don't change the name, just change the signature.

> 
> Signed-off-by: Herve Codina <herve.codina@bootlin.com>
> ---
>  checks.c   |  5 ++---
>  dtc.h      |  4 ++--
>  livetree.c | 18 +++++++++++++++++-
>  3 files changed, 21 insertions(+), 6 deletions(-)
> 
> diff --git a/checks.c b/checks.c
> index 75040c0..0a855f9 100644
> --- a/checks.c
> +++ b/checks.c
> @@ -439,7 +439,6 @@ static void check_duplicate_label(struct check *c, struct dt_info *dti,
>  				  const char *label, struct node *node,
>  				  struct property *prop, struct marker *mark)
>  {
> -	struct node *dt = dti->dt;
>  	struct node *othernode = NULL;
>  	struct property *otherprop = NULL;
>  	struct marker *othermark = NULL;
> @@ -449,8 +448,8 @@ static void check_duplicate_label(struct check *c, struct dt_info *dti,
>  	if (!othernode)
>  		otherprop = dti_get_property_by_label(dti, label, &othernode);
>  	if (!othernode)
> -		othermark = get_marker_label(dt, label, &othernode,
> -					       &otherprop);
> +		othermark = dti_get_marker_label(dti, label, &othernode,
> +						 &otherprop);
>  
>  	if (!othernode)
>  		return;
> diff --git a/dtc.h b/dtc.h
> index 399e7fa..d45a84c 100644
> --- a/dtc.h
> +++ b/dtc.h
> @@ -318,8 +318,6 @@ const char *get_unitname(struct node *node);
>  struct property *get_property(struct node *node, const char *propname);
>  cell_t propval_cell(struct property *prop);
>  cell_t propval_cell_n(struct property *prop, unsigned int n);
> -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);
>  
>  uint32_t guess_boot_cpuid(struct node *tree);
> @@ -358,6 +356,8 @@ cell_t dti_get_node_phandle(struct dt_info *dti, struct node *node);
>  struct property *dti_get_property_by_label(struct dt_info *dti,
>  					   const char *label,
>  					   struct node **node);
> +struct marker *dti_get_marker_label(struct dt_info *dti, const char *label,
> +				    struct node **node, struct property **prop);
>  
>  /* DTS version flags definitions */
>  #define DTSF_V1		0x0001	/* /dts-v1/ */
> diff --git a/livetree.c b/livetree.c
> index d023075..79f7b55 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -620,7 +620,7 @@ static struct property *get_property_by_label(struct node *tree, const char *lab
>  	return NULL;
>  }
>  
> -struct marker *get_marker_label(struct node *tree, const char *label,
> +static struct marker *get_marker_label(struct node *tree, const char *label,
>  				struct node **node, struct property **prop)
>  {
>  	struct marker *m;
> @@ -853,6 +853,22 @@ struct property *dti_get_property_by_label(struct dt_info *dti,
>  	return NULL;
>  }
>  
> +struct marker *dti_get_marker_label(struct dt_info *dti, const char *label,
> +				    struct node **node, struct property **prop)
> +{
> +	struct marker *marker;
> +
> +	if (dti->dt) {
> +		marker = get_marker_label(dti->dt, label, node, prop);
> +		if (marker)
> +			return marker;
> +	}
> +
> +	*prop = NULL;
> +	*node = NULL;
> +	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 46/77] dtc: Introduce dti_get_marker_label()
Posted by Herve Codina 2 weeks, 5 days ago
On Thu, 15 Jan 2026 17:51:30 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Mon, Jan 12, 2026 at 03:19:36PM +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
> > 
> > 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_marker_label().
> > 
> > dti_get_marker_label() retrieves a marker and its related node and
> > property based on the label value. It behaves in the same way as
> > get_marker_label() 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.  
> 
> For all of these functions, if the new one is basically replacing the
> old one, don't change the name, just change the signature.

The old function is kept an used internally (move to static).
It is not a simple replacement.

When I introduce orphan node later on, those dti_xxxx() functions call
the old function multiple times. One call for the root tree and other calls
for orphan trees.

But anyway, If you prefer keeping the old name with a new signature,
I can do the following:
 - move function_name() to __function_name()
 - Update the function_name() signature and call __function_name().

Best regards
Hervé
Re: [RFC PATCH 46/77] dtc: Introduce dti_get_marker_label()
Posted by David Gibson 2 weeks, 3 days ago
On Mon, Jan 19, 2026 at 05:02:40PM +0100, Herve Codina wrote:
> On Thu, 15 Jan 2026 17:51:30 +1100
> David Gibson <david@gibson.dropbear.id.au> wrote:
> 
> > On Mon, Jan 12, 2026 at 03:19:36PM +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
> > > 
> > > 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_marker_label().
> > > 
> > > dti_get_marker_label() retrieves a marker and its related node and
> > > property based on the label value. It behaves in the same way as
> > > get_marker_label() 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.  
> > 
> > For all of these functions, if the new one is basically replacing the
> > old one, don't change the name, just change the signature.
> 
> The old function is kept an used internally (move to static).
> It is not a simple replacement.

It's a replacement in the sense that all the existing callers are
moving to the new function.

> When I introduce orphan node later on, those dti_xxxx() functions call
> the old function multiple times. One call for the root tree and other calls
> for orphan trees.

> But anyway, If you prefer keeping the old name with a new signature,
> I can do the following:
>  - move function_name() to __function_name()
>  - Update the function_name() signature and call __function_name().

That's a better plan.  Except don't use __function_name().  _ prefixed
names are reserved for the C library.  Use a _ suffix instead
(e.g. see fdt_get_property_by_offset_()).

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