From c4460b9d43f6d3d636cf2b374e1591d7e49c85d3 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 22 Mar 2021 12:20:26 +0100 Subject: of: Return copy of live tree as fixed tree the of fixups modify the the tree passed to them. It is undesired that these modify the live tree, so when we are requested to return the fixed live tree then make a copy first. Signed-off-by: Sascha Hauer --- common/oftree.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'common/oftree.c') diff --git a/common/oftree.c b/common/oftree.c index 075b9d6b8b..60d4327155 100644 --- a/common/oftree.c +++ b/common/oftree.c @@ -319,21 +319,27 @@ int of_fix_tree(struct device_node *node) struct fdt_header *of_get_fixed_tree(struct device_node *node) { int ret; - struct fdt_header *fdt; + struct fdt_header *fdt = NULL; + struct device_node *freenp = NULL; if (!node) { node = of_get_root_node(); if (!node) return NULL; + + freenp = node = of_copy_node(NULL, node); + if (!node) + return NULL; } ret = of_fix_tree(node); if (ret) - return NULL; + goto out; fdt = of_flatten_dtb(node); - if (!fdt) - return NULL; + +out: + of_delete_node(freenp); return fdt; } -- cgit v1.2.3