[PATCH v4 5/6] of/overlay: rewrite /aliases path values to live-tree paths
From: Abdurrahman Hussain
Date: Tue Jul 21 2026 - 21:02:24 EST
/aliases entries added by an overlay reference labeled nodes inside
the overlay via '&label' in the .dtso. dtc renders those references
as string paths at compile time, but the paths encode the overlay's
internal fragment layout (e.g. "/fragment@1/__overlay__/fpga@0/i2c@40000")
rather than the location where the node will live after apply.
Currently only /__symbols__ has its property values rewritten from
overlay-internal paths to live-tree paths by dup_and_fixup_symbol_prop().
/aliases values fall through the plain __of_prop_dup() path and are
copied byte-for-byte, so of_find_node_by_path() on such a value returns
NULL, of_alias_get_id() reports -ENODEV — and the reconfig notifier
added earlier in this series sees uninterpretable paths and can't
populate aliases_lookup for overlay-declared aliases.
The values in /aliases follow the same textual convention as
/__symbols__, so we can reuse the existing rewriter. Detect the
/aliases target node (of_node_is_aliases(), the same predicate the
reconfig notifier uses) and offer every non-pseudo property to
dup_and_fixup_symbol_prop(); the previous patch made its return value
carry the distinction this needs. A value that resolves inside one of
the overlay's fragments is stored rewritten. -ENODEV means the value
is not a path into this overlay — legacy string aliases like "ttyS0",
or absolute live-tree paths — and is copied verbatim, as before this
series. -EINVAL means the value is not a valid non-empty C string; it
is also copied verbatim, but with a warning: consumers
(of_alias_create() and the alias path lookup) validate before
dereferencing, so a malformed alias is inert rather than a reason to
reject an otherwise-valid overlay that applied cleanly before this
series. Only -ENOMEM fails the apply.
Matching on where the value resolves rather than on a "/fragment@"
name prefix matters: init_overlay_changeset() accepts fragments with
any node name, and dtc emits the actual fragment name into the alias
value, so a prefix test would silently leave a hand-named fragment's
alias unrewritten (and misroute a live-tree path that happens to
start with "/fragment@").
Pseudo-properties (name, phandle, linux,phandle) are exempt from the
/aliases handling: the is_pseudo_property() skip at the top of
add_changeset_property() only covers targets already in the live
tree, so a phandle of a newly created /aliases node would otherwise
reach the rewriter — and a phandle value is a raw cell, not a C
string. Such properties take the plain __of_prop_dup() path as
before this patch; of_alias_create() skips them at notifier time.
Assisted-by: Claude:claude-fable-5 [Claude Code]
Signed-off-by: Abdurrahman Hussain <abdurrahman@xxxxxxxxxx>
---
drivers/of/overlay.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index ad4e50482515..2a37b5260ba7 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -356,6 +356,19 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
new_prop = dup_and_fixup_symbol_prop(ovcs, overlay_prop);
if (IS_ERR(new_prop))
return PTR_ERR(new_prop);
+ } else if (!is_pseudo_property(overlay_prop->name) &&
+ of_node_is_aliases(target->np)) {
+ /* rewrite overlay-internal alias values to live-tree paths */
+ new_prop = dup_and_fixup_symbol_prop(ovcs, overlay_prop);
+ if (new_prop == ERR_PTR(-ENOMEM))
+ return -ENOMEM;
+ if (IS_ERR(new_prop)) {
+ if (new_prop == ERR_PTR(-EINVAL))
+ pr_warn("%pOF/%s is not a valid string; alias will be inert\n",
+ target->np, overlay_prop->name);
+ /* not overlay-internal: copy verbatim, consumers validate */
+ new_prop = __of_prop_dup(overlay_prop, GFP_KERNEL);
+ }
} else {
new_prop = __of_prop_dup(overlay_prop, GFP_KERNEL);
}
--
2.54.0