[PATCH v4 5/6] of: implement of_move_node helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Reparenting nodes can be a useful thing to do in fixups. Add a helper
for that.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 drivers/of/base.c | 18 ++++++++++++++++++
 include/of.h      |  1 +
 2 files changed, 19 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index e3416b5b75a7..43a4a923d9c5 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2695,6 +2695,24 @@ void of_delete_node(struct device_node *node)
 	free(node);
 }
 
+void of_move_node(struct device_node *parent, struct device_node *node)
+{
+	if (!node)
+		return;
+
+	list_del(&node->list);
+	list_del(&node->parent_list);
+
+	free(node->full_name);
+	node->full_name = basprintf("%s/%s", parent->full_name, node->name);
+
+	if (!node->parent)
+		return;
+
+	list_add(&node->list, &parent->list);
+	list_add_tail(&node->parent_list, &parent->children);
+}
+
 /*
  * of_find_node_by_chosen - Find a node given a chosen property pointing at it
  * @propname:   the name of the property containing a path or alias
diff --git a/include/of.h b/include/of.h
index 0037bad6c4d7..686c1632c267 100644
--- a/include/of.h
+++ b/include/of.h
@@ -187,6 +187,7 @@ extern struct device_node *of_create_node(struct device_node *root,
 extern void of_merge_nodes(struct device_node *np, const struct device_node *other);
 extern struct device_node *of_copy_node(struct device_node *parent,
 				const struct device_node *other);
+void of_move_node(struct device_node *parent, struct device_node *node);
 extern struct device_node *of_dup(const struct device_node *root);
 extern void of_delete_node(struct device_node *node);
 
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux