From: Jonas Karlman Date: Sun, 4 Aug 2024 15:05:51 +0000 (+0000) Subject: dm: core: regmap: Avoid multiple calls to ofnode_get_parent() X-Git-Url: http://git.dujemihanovic.xyz/html/index.html?a=commitdiff_plain;h=6f5b1686610119c321962ba2224bda6d71fc8968;p=u-boot.git dm: core: regmap: Avoid multiple calls to ofnode_get_parent() 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 Reviewed-by: Simon Glass --- diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c index 304d5b02bc..5cb5fa2734 100644 --- a/drivers/core/regmap.c +++ b/drivers/core/regmap.c @@ -168,18 +168,21 @@ static int init_range(ofnode node, struct regmap_range *range, int addr_len, int regmap_init_mem_index(ofnode node, struct regmap **mapp, int index) { + ofnode parent; struct regmap *map; int addr_len, size_len; int ret; - addr_len = ofnode_read_simple_addr_cells(ofnode_get_parent(node)); + parent = ofnode_get_parent(node); + + addr_len = ofnode_read_simple_addr_cells(parent); if (addr_len < 0) { dm_warn("%s: Error while reading the addr length (ret = %d)\n", ofnode_get_name(node), addr_len); return addr_len; } - size_len = ofnode_read_simple_size_cells(ofnode_get_parent(node)); + size_len = ofnode_read_simple_size_cells(parent); if (size_len < 0) { dm_warn("%s: Error while reading the size length: (ret = %d)\n", ofnode_get_name(node), size_len); @@ -241,6 +244,7 @@ int regmap_init_mem_range(ofnode node, ulong r_start, ulong r_size, int regmap_init_mem(ofnode node, struct regmap **mapp) { + ofnode parent; struct regmap_range *range; struct regmap *map; int count; @@ -249,14 +253,16 @@ int regmap_init_mem(ofnode node, struct regmap **mapp) int index; int ret; - addr_len = ofnode_read_simple_addr_cells(ofnode_get_parent(node)); + parent = ofnode_get_parent(node); + + addr_len = ofnode_read_simple_addr_cells(parent); if (addr_len < 0) { dm_warn("%s: Error while reading the addr length (ret = %d)\n", ofnode_get_name(node), addr_len); return addr_len; } - size_len = ofnode_read_simple_size_cells(ofnode_get_parent(node)); + size_len = ofnode_read_simple_size_cells(parent); if (size_len < 0) { dm_warn("%s: Error while reading the size length: (ret = %d)\n", ofnode_get_name(node), size_len);