From 35c869cfe698bf7e6afdf55b7bd33c0b26250e38 Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Fri, 8 Sep 2023 00:39:16 +0900 Subject: [PATCH] kboot: Make dt_get_or_add_reserved_mem mutate existing nodes This means we can use it with pre-created nodes in the DT. Signed-off-by: Hector Martin --- src/kboot.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/kboot.c b/src/kboot.c index 50ae6207..c7a27f22 100644 --- a/src/kboot.c +++ b/src/kboot.c @@ -1209,21 +1209,20 @@ static int dt_get_or_add_reserved_mem(const char *node_name, const char *compat, bail("FDT: '/reserved-memory' not found\n"); int node = fdt_subnode_offset(dt, resv_node, node_name); - if (node >= 0) - return node; + if (node < 0) { + node = fdt_add_subnode(dt, resv_node, node_name); + if (node < 0) + bail("FDT: failed to add node '%s' to '/reserved-memory'\n", node_name); - node = fdt_add_subnode(dt, resv_node, node_name); - if (node < 0) - bail("FDT: failed to add node '%s' to '/reserved-memory'\n", node_name); + uint32_t phandle; + ret = fdt_generate_phandle(dt, &phandle); + if (ret) + bail("FDT: failed to generate phandle: %d\n", ret); - uint32_t phandle; - ret = fdt_generate_phandle(dt, &phandle); - if (ret) - bail("FDT: failed to generate phandle: %d\n", ret); - - ret = fdt_setprop_u32(dt, node, "phandle", phandle); - if (ret != 0) - bail("FDT: couldn't set '%s.phandle' property: %d\n", node_name, ret); + ret = fdt_setprop_u32(dt, node, "phandle", phandle); + if (ret != 0) + bail("FDT: couldn't set '%s.phandle' property: %d\n", node_name, ret); + } u64 reg[2] = {cpu_to_fdt64(paddr), cpu_to_fdt64(size)}; ret = fdt_setprop(dt, node, "reg", reg, sizeof(reg));