[RFC PATCH v2 36/74] dtc: Change get_node_by_path() signature to take dt_info
From: Herve Codina
Date: Wed Aug 26 2026 - 06:07:15 EST
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 orphan nodes introduction, move get_node_by_path() parameter
one level up and use dt_info struct instead of the 'root' tree (i.e.
dti->dt).
This change doesn't lead to any functional changes.
Signed-off-by: Herve Codina <herve.codina@xxxxxxxxxxx>
---
checks.c | 2 +-
dtc.h | 3 ++-
livetree.c | 20 ++++++++++++++------
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/checks.c b/checks.c
index 1332acc4..3b852a9d 100644
--- a/checks.c
+++ b/checks.c
@@ -748,7 +748,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 || !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 61521329..a07df2c8 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 *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 130ddf25..0120efd2 100644
--- a/livetree.c
+++ b/livetree.c
@@ -771,7 +771,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;
@@ -789,7 +789,7 @@ struct node *get_node_by_path(struct node *tree, const char *path)
for_each_child(tree, child) {
if (p && strprefixeq(path, (size_t)(p - path), child->name))
- return get_node_by_path(child, p+1);
+ return get_node_by_path_(child, p+1);
else if (!p && streq(path, child->name))
return child;
}
@@ -892,11 +892,19 @@ struct node *get_node_by_ref(struct node *tree, const char *ref)
}
if (path)
- target = get_node_by_path(target, path);
+ target = get_node_by_path_(target, path);
return target;
}
+struct node *get_node_by_path(struct dt_info *dti, const char *path)
+{
+ if (dti->dt)
+ return get_node_by_path_(dti->dt, path);
+
+ return NULL;
+}
+
static void add_phandle_property(struct node *node,
const char *name, int format)
{
@@ -940,7 +948,7 @@ uint32_t guess_boot_cpuid(struct node *tree)
struct node *cpus, *bootcpu;
struct property *reg;
- cpus = get_node_by_path(tree, "/cpus");
+ cpus = get_node_by_path_(tree, "/cpus");
if (!cpus)
return 0;
@@ -1415,7 +1423,7 @@ void generate_labels_from_tree(struct dt_info *dti, const char *name)
for_each_property(an, p) {
struct node *labeled_node;
- labeled_node = get_node_by_path(dti->dt, p->val.val);
+ labeled_node = get_node_by_path_(dti->dt, p->val.val);
if (labeled_node)
add_label(&labeled_node->labels, p->name);
else if (quiet < 1)
@@ -1497,7 +1505,7 @@ void fixup_phandles(struct dt_info *dti, const char *name)
*/
*(propname - 1) = '\0';
- n = get_node_by_path(dti->dt, fv);
+ n = get_node_by_path_(dti->dt, fv);
if (!n && quiet < 1)
fprintf(stderr, "Warning: Label %s references non-existing node %s\n",
fp->name, fv);
--
2.55.0