[RFC PATCH 51/77] dtc: Avoid NULL fullpath for nodes in orphan trees

Herve Codina posted 77 patches 3 weeks, 5 days ago
[RFC PATCH 51/77] dtc: Avoid NULL fullpath for nodes in orphan trees
Posted by Herve Codina 3 weeks, 5 days ago
Orphan nodes have been introduced recently.

The process_checks() function uses fullpath in several places and
crashes due NULL pointer dereferences if fullpath is NULL.

In order to have process_checks() function running without crashes with
orphan trees (i.e. trees based on orphan nodes), the fullpath of node
available in those orphan trees must not be NULL.

Fullpath values are built by dti_fill_fullpaths(). Update it to handle
fullpath in trees based on orphan nodes.

Use a simple "__orphan__/" prefix to avoid the NULL pointer and to be
distinct from the root node ("/" prefix).

It is worth noting that this "__orphan__/" prefix is a temporary prefix
and it will be change later when support for reference by path involving
nodes in orphan tree is added.

Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
 dtc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/dtc.c b/dtc.c
index 59f4d77..5cf8f31 100644
--- a/dtc.c
+++ b/dtc.c
@@ -47,9 +47,14 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
 
 static void dti_fill_fullpaths(struct dt_info *dti)
 {
+	struct node *orphan;
+
 	/* Fill fullpaths for the root node */
 	if (dti->dt)
 		fill_fullpaths(dti->dt, "");
+
+	for_each_orphan(dti->orphanlist, orphan)
+		fill_fullpaths(orphan, "__orphan__/");
 }
 
 /* Usage related data. */
-- 
2.52.0
Re: [RFC PATCH 51/77] dtc: Avoid NULL fullpath for nodes in orphan trees
Posted by David Gibson 3 weeks, 3 days ago
On Mon, Jan 12, 2026 at 03:19:41PM +0100, Herve Codina wrote:
> Orphan nodes have been introduced recently.
> 
> The process_checks() function uses fullpath in several places and
> crashes due NULL pointer dereferences if fullpath is NULL.
> 
> In order to have process_checks() function running without crashes with
> orphan trees (i.e. trees based on orphan nodes), the fullpath of node
> available in those orphan trees must not be NULL.
> 
> Fullpath values are built by dti_fill_fullpaths(). Update it to handle
> fullpath in trees based on orphan nodes.
> 
> Use a simple "__orphan__/" prefix to avoid the NULL pointer and to be
> distinct from the root node ("/" prefix).
> 
> It is worth noting that this "__orphan__/" prefix is a temporary prefix
> and it will be change later when support for reference by path involving
> nodes in orphan tree is added.

It might be simpler to eliminate the fullpath field entirely, and
instead have a function that calculates fullpaths at the point you
need them.

> 
> Signed-off-by: Herve Codina <herve.codina@bootlin.com>
> ---
>  dtc.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/dtc.c b/dtc.c
> index 59f4d77..5cf8f31 100644
> --- a/dtc.c
> +++ b/dtc.c
> @@ -47,9 +47,14 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
>  
>  static void dti_fill_fullpaths(struct dt_info *dti)
>  {
> +	struct node *orphan;
> +
>  	/* Fill fullpaths for the root node */
>  	if (dti->dt)
>  		fill_fullpaths(dti->dt, "");
> +
> +	for_each_orphan(dti->orphanlist, orphan)
> +		fill_fullpaths(orphan, "__orphan__/");
>  }
>  
>  /* Usage related data. */
> -- 
> 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 51/77] dtc: Avoid NULL fullpath for nodes in orphan trees
Posted by Herve Codina 2 weeks, 5 days ago
On Thu, 15 Jan 2026 17:56:07 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Mon, Jan 12, 2026 at 03:19:41PM +0100, Herve Codina wrote:
> > Orphan nodes have been introduced recently.
> > 
> > The process_checks() function uses fullpath in several places and
> > crashes due NULL pointer dereferences if fullpath is NULL.
> > 
> > In order to have process_checks() function running without crashes with
> > orphan trees (i.e. trees based on orphan nodes), the fullpath of node
> > available in those orphan trees must not be NULL.
> > 
> > Fullpath values are built by dti_fill_fullpaths(). Update it to handle
> > fullpath in trees based on orphan nodes.
> > 
> > Use a simple "__orphan__/" prefix to avoid the NULL pointer and to be
> > distinct from the root node ("/" prefix).
> > 
> > It is worth noting that this "__orphan__/" prefix is a temporary prefix
> > and it will be change later when support for reference by path involving
> > nodes in orphan tree is added.  
> 
> It might be simpler to eliminate the fullpath field entirely, and
> instead have a function that calculates fullpaths at the point you
> need them.

I am not sure it will be simpler.

I would prefer keeping dti_fill_fullpaths() for the moment.

This could be change later when things are more stable.

Many thinks are under discussion and changing all users of the the fullpath
field now will introduce more complexity which is not needed right now.

Best regards,
Hervé