Re: [RFC PATCH 49/77] dtc: Handle orphan nodes in dti_get_xxx_by_yyy()

David Gibson <[email protected]> Thu, 15 Jan 2026 17:55:05 +1100
Newsgroups org.kernel.vger.devicetree-spec,org.kernel.vger.devicetree-compiler,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-kernel
Message-ID <aWiPSQOCipvvItyo@zatzit>
On Mon, Jan 12, 2026 at 03:19:39PM +0100, Herve Codina wrote:
> Orphan nodes have been introduced recently.
> 
> Retrieving a node, a property and/or a marker from an orphan node tree
> is perfectly legit.
> 
> Those retrievals are performed by the dti_get_xxx_by_yyy() functions
> family.
> 
> Update them to handle orphan nodes.

I think at least some of the orphan node stuff can be separated from
the import/export symbol stuff, and dtb changes.  That can be reviewed
and merged first, which will simplify the review task.

The idea is this:  at the moment, when we have multiple tree sections
in the dts, we merge them all together into a single tree as we parse.
The idea would be that we first make a list of all those sections,
then perform the merge as a separate step from parsing.

> 
> Signed-off-by: Herve Codina <[email protected]>
> ---
>  livetree.c | 42 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 42 insertions(+)
> 
> diff --git a/livetree.c b/livetree.c
> index 057997a..fa9daff 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -789,6 +789,7 @@ static struct node *get_node_by_ref(struct node *tree, const char *ref)
>  
>  struct node *dti_get_node_by_path(struct dt_info *dti, const char *path)
>  {
> +	struct node *orphan;
>  	struct node *node;
>  
>  	if (dti->dt) {
> @@ -797,11 +798,18 @@ struct node *dti_get_node_by_path(struct dt_info *dti, const char *path)
>  			return node;
>  	}
>  
> +	for_each_orphan(dti->orphanlist, orphan) {
> +		node = get_node_by_path(orphan, path);
> +		if (node)
> +			return node;
> +	}
> +
>  	return NULL;
>  }
>  
>  struct node *dti_get_node_by_label(struct dt_info *dti, const char *label)
>  {
> +	struct node *orphan;
>  	struct node *node;
>  
>  	if (dti->dt) {
> @@ -810,11 +818,18 @@ struct node *dti_get_node_by_label(struct dt_info *dti, const char *label)
>  			return node;
>  	}
>  
> +	for_each_orphan(dti->orphanlist, orphan) {
> +		node = get_node_by_label(orphan, label);
> +		if (node)
> +			return node;
> +	}
> +
>  	return NULL;
>  }
>  
>  struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle)
>  {
> +	struct node *orphan;
>  	struct node *node;
>  
>  	if (dti->dt) {
> @@ -823,11 +838,18 @@ struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle)
>  			return node;
>  	}
>  
> +	for_each_orphan(dti->orphanlist, orphan) {
> +		node = get_node_by_phandle(orphan, phandle);
> +		if (node)
> +			return node;
> +	}
> +
>  	return NULL;
>  }
>  
>  struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref)
>  {
> +	struct node *orphan;
>  	struct node *node;
>  
>  	if (dti->dt) {
> @@ -836,6 +858,12 @@ struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref)
>  			return node;
>  	}
>  
> +	for_each_orphan(dti->orphanlist, orphan) {
> +		node = get_node_by_ref(orphan, ref);
> +		if (node)
> +			return node;
> +	}
> +
>  	return NULL;
>  }
>  
> @@ -844,6 +872,7 @@ struct property *dti_get_property_by_label(struct dt_info *dti,
>  					   struct node **node)
>  {
>  	struct property *property;
> +	struct node *orphan;
>  
>  	if (dti->dt) {
>  		property = get_property_by_label(dti->dt, label, node);
> @@ -851,6 +880,12 @@ struct property *dti_get_property_by_label(struct dt_info *dti,
>  			return property;
>  	}
>  
> +	for_each_orphan(dti->orphanlist, orphan) {
> +		property = get_property_by_label(orphan, label, node);
> +		if (property)
> +			return property;
> +	}
> +
>  	*node = NULL;
>  	return NULL;
>  }
> @@ -859,6 +894,7 @@ struct marker *dti_get_marker_label(struct dt_info *dti, const char *label,
>  				    struct node **node, struct property **prop)
>  {
>  	struct marker *marker;
> +	struct node *orphan;
>  
>  	if (dti->dt) {
>  		marker = get_marker_label(dti->dt, label, node, prop);
> @@ -866,6 +902,12 @@ struct marker *dti_get_marker_label(struct dt_info *dti, const char *label,
>  			return marker;
>  	}
>  
> +	for_each_orphan(dti->orphanlist, orphan) {
> +		marker = get_marker_label(orphan, label, node, prop);
> +		if (marker)
> +			return marker;
> +	}
> +
>  	*prop = NULL;
>  	*node = NULL;
>  	return NULL;
> -- 
> 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
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmloj0gACgkQzQJF27ox
2Gc7eRAAqjX4r6lNs0/gKO6AEGXtNZxrU4qaYqpu6f46Q+y2hq1Smi6RAQ6uXsz5
huKjL2mbwGICIx6JiwXJPjGIYDbsYsvuMvawkVXvKjmFyMtVOfmS5hJmduG5m3Ov
AuUy2nhul6NUhJRnoh1BtOA4CQfiR1ag4dEmh4SJEsobfDriC8Wff/pmnIr5s1oV
LIPECrbf7N4zoU0QKn5fRqEVnFipHxfJtovG8s3BoA/rZmZRS8KOn/zGptrgxzoL
T9zVtDhvG4MLSfJOJyaTgxJVXYoEwXgy6y0GIg743oMupLmWTnCafSukQ/o6msJA
KE5itFLLiIN0bE50Sfk0QFqdW+haMe8Cteh1ozX71n7RGF4q1SEyWnGqN9Mxgmbu
26qg7BUfRH7Y4svfnODsym9o9jygoUBh9GdeDUSVN+jrD2RhiGKKrRFi8le2iFzL
a9Tag81TtQXGfXYi6X8g+OPX0yU8qXFgedop/+7ULZiY4i8FmSf0qOwCwMWXkoVy
0WlMa5zev9czou/H6Loic/VbeceRiS0ZmAoGFFJgJIBleyMpk6stNNS0vF1laUBX
6nC5yaHgC8se7roZEgYKh81ApPjgRB2BqHC44ZfTKtehTNPCye/DILzENxPOhsHS
TeMp7zzfommBMmrTfQgcUCJsbNt7nAd7gwz8yIba5h2YyDkNjAA=
=XHOw
-----END PGP SIGNATURE-----