aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver O'Halloran <oohall@gmail.com>2017-01-12 14:54:08 +1100
committerStewart Smith <stewart@linux.vnet.ibm.com>2018-01-05 10:54:52 +1100
commit0562c4862d178caede13e27e6eb554ec4ae44888 (patch)
tree85b8b9b44b1cceb5e48689c572f02148eb53698b
parent43290f90e46d632ed5a314292c317e6f813c3b74 (diff)
downloadskiboot-0562c4862d178caede13e27e6eb554ec4ae44888.zip
skiboot-0562c4862d178caede13e27e6eb554ec4ae44888.tar.gz
skiboot-0562c4862d178caede13e27e6eb554ec4ae44888.tar.bz2
dt: add dt_new_check()
This is similar to dt_new(), but if the node already exists it will return the existing node. This is useful because some init code depends on the presence of certain nodes, but where the node is actually created is unimportant. Signed-off-by: Oliver O'Halloran <oohall@gmail.com> Reviewed-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com> Reviewed-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com> (cherry picked from commit 371e88e2366215b5a033c2cedaf7486d1e66914d) Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r--core/device.c14
-rw-r--r--include/device.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/core/device.c b/core/device.c
index 63b5df8..a9c7ebe 100644
--- a/core/device.c
+++ b/core/device.c
@@ -352,6 +352,20 @@ struct dt_node *dt_find_by_name(struct dt_node *root, const char *name)
return NULL;
}
+
+struct dt_node *dt_new_check(struct dt_node *parent, const char *name)
+{
+ struct dt_node *node = dt_find_by_name(parent, name);
+
+ if (!node) {
+ node = dt_new(parent, name);
+ assert(node);
+ }
+
+ return node;
+}
+
+
struct dt_node *dt_find_by_phandle(struct dt_node *root, u32 phandle)
{
struct dt_node *node;
diff --git a/include/device.h b/include/device.h
index 4198a41..1ad403f 100644
--- a/include/device.h
+++ b/include/device.h
@@ -67,6 +67,7 @@ struct dt_node *dt_new_addr(struct dt_node *parent, const char *name,
uint64_t unit_addr);
struct dt_node *dt_new_2addr(struct dt_node *parent, const char *name,
uint64_t unit_addr0, uint64_t unit_addr1);
+struct dt_node *dt_new_check(struct dt_node *parent, const char *name);
/* Copy node to new parent, including properties and subnodes */
struct dt_node *dt_copy(struct dt_node *node, struct dt_node *parent);