diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-02-19 23:36:12 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-03-06 11:41:27 +0100 |
commit | 69c54bc9398bf33680f095c6495e957293a868bb (patch) | |
tree | a986e841aa82913562701835e433ffc3ef8cfce4 /drivers/of | |
parent | c1f4371f66732a6bb0f39e5e385d85321ac9810b (diff) | |
download | barebox-69c54bc9398bf33680f095c6495e957293a868bb.tar.gz barebox-69c54bc9398bf33680f095c6495e957293a868bb.tar.xz |
of: unflatten: allocate root node explicitly
By doing so of_new_node does not depend on the global root_node
anymore.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/base.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index fd9b8e14a3..d134f1ef3a 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -946,7 +946,7 @@ int of_unflatten_dtb(struct fdt_header *fdt) const struct fdt_property *fdt_prop; const char *pathp; int depth = 10000; - struct device_node *node = NULL, *n; + struct device_node *node = NULL, *n, *root = NULL; struct property *p; nodeoffset = fdt_path_offset(fdt, "/"); @@ -959,6 +959,10 @@ int of_unflatten_dtb(struct fdt_header *fdt) return -EINVAL; } + root = of_new_node(NULL, NULL); + if (!root) + return -ENOMEM; + while (1) { tag = fdt_next_tag(fdt, nodeoffset, &nextoffset); switch (tag) { @@ -968,11 +972,14 @@ int of_unflatten_dtb(struct fdt_header *fdt) if (pathp == NULL) pathp = "/* NULL pointer error */"; - n = of_find_child(node, pathp); - if (n) { - node = n; + if (!node) { + node = root; } else { - node = of_new_node(node, pathp); + if ((n = of_find_child(node, pathp))) { + node = n; + } else { + node = of_new_node(node, pathp); + } } break; case FDT_END_NODE: |