]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: ofnode: Avoid multiple calls to ofnode_get_parent()
authorJonas Karlman <jonas@kwiboo.se>
Sun, 4 Aug 2024 15:05:50 +0000 (15:05 +0000)
committerTom Rini <trini@konsulko.com>
Tue, 27 Aug 2024 20:32:49 +0000 (14:32 -0600)
Until a live tree is used in U-Boot proper after relocation, use of
ofnode_get_parent() will trigger a call to the very expensive
fdt_parent_offset() as detailed by the function documentation:

  NOTE: This function is expensive, as it must scan the device tree
  structure from the start to nodeoffset, *twice*.

Re-use the returned value from a single call instead of having to make
multiple calls for same node.

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/core/ofnode.c

index 4d563b47a5a3988c93e54ed7284bfaa508f20170..7e3b3719d18fe8f961129e0c408c419ad5103030 100644 (file)
@@ -762,8 +762,9 @@ static fdt_addr_t __ofnode_get_addr_size_index(ofnode node, int index,
                        return of_read_number(prop_val, na);
                }
        } else {
-               na = ofnode_read_simple_addr_cells(ofnode_get_parent(node));
-               ns = ofnode_read_simple_size_cells(ofnode_get_parent(node));
+               ofnode parent = ofnode_get_parent(node);
+               na = ofnode_read_simple_addr_cells(parent);
+               ns = ofnode_read_simple_size_cells(parent);
                return fdtdec_get_addr_size_fixed(ofnode_to_fdt(node),
                                                  ofnode_to_offset(node), "reg",
                                                  index, na, ns, size,