[PATCH] of: address: Fix bug to get the highest cpu address of subtrees for dma

From: Joonwon Kang
Date: Sun Jul 27 2025 - 14:01:40 EST


The function of_dma_get_max_cpu_address() for a device node should choose
the highest cpu address among the ones that subtree nodes can access.
However, there was a bug of choosing the lowest cpu address and this
commit is to fix it.

Signed-off-by: Joonwon Kang <kjw1627@xxxxxxxxx>
---
drivers/of/address.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index f0f8f0dd191c..5e984e0d372b 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -969,6 +969,7 @@ phys_addr_t __init of_dma_get_max_cpu_address(struct device_node *np)
{
phys_addr_t max_cpu_addr = PHYS_ADDR_MAX;
struct of_range_parser parser;
+ phys_addr_t max_subtree_max_addr = PHYS_ADDR_MAX;
phys_addr_t subtree_max_addr;
struct device_node *child;
struct of_range range;
@@ -992,10 +993,17 @@ phys_addr_t __init of_dma_get_max_cpu_address(struct device_node *np)

for_each_available_child_of_node(np, child) {
subtree_max_addr = of_dma_get_max_cpu_address(child);
- if (max_cpu_addr > subtree_max_addr)
- max_cpu_addr = subtree_max_addr;
+ if (subtree_max_addr == PHYS_ADDR_MAX)
+ continue;
+
+ if (max_subtree_max_addr == PHYS_ADDR_MAX)
+ max_subtree_max_addr = subtree_max_addr;
+ else
+ max_subtree_max_addr = max(max_subtree_max_addr, subtree_max_addr);
}

+ max_cpu_addr = min(max_cpu_addr, max_subtree_max_addr);
+
return max_cpu_addr;
}

--
2.46.0