[PATCH 1/4] of: fall back to parent-prefixed encoding when address translation fails

Sascha Hauer <[email protected]>
Newsgroups org.infradead.lists.barebox
Message-ID <[email protected]>
of_get_reproducible_name() formatted the result of of_translate_address()
as [0x%llx] without checking for OF_BAD_ADDR ((u64)-1). For any node
whose reg can't be translated through the parent's ranges - notably PCI
child nodes whose reg[0] encodes a config-space address (space=0), which
host bridges don't list in ranges - this produced [0xffffffffffffffff]
for every such node, collapsing distinct nodes onto the same name and
making of_find_node_by_reproducible_name() return the wrong sibling.

Fall through to the existing parent-prefixed {offset} branch when
translation fails, so untranslatable siblings get disambiguated by
their parent chain.

Assisted-by: Claude Opus 4.7
Signed-off-by: Sascha Hauer <[email protected]>
---
 drivers/of/base.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 5297894f60..1244664827 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -3368,7 +3368,14 @@ char *of_get_reproducible_name(struct device_node *node)
 
 	if (node->parent && of_get_property(node->parent, "ranges", NULL)) {
 		addr = of_translate_address(node, reg);
-		return basprintf("[0x%llx]", addr);
+		if (addr != OF_BAD_ADDR)
+			return basprintf("[0x%llx]", addr);
+		/*
+		 * Untranslatable - e.g. a PCI config-space address whose
+		 * tag (space=0) doesn't appear in the parent's ranges.
+		 * Fall through to the parent-prefixed encoding so distinct
+		 * untranslatable nodes don't all collide on OF_BAD_ADDR.
+		 */
 	}
 
 	na = of_n_addr_cells(node);

-- 
2.47.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.