[05/18] software_node: Alter software_node_unregister_nodes() to unregister the array in reverse order

Message ID 20201130133129.1024662-6-djrscally@gmail.com
State New
Headers show
  • Add functionality to ipu3-cio2 driver allowing software_node connections to sensors on platforms designed for Windows
Related show

Commit Message

Daniel Scally Nov. 30, 2020, 1:31 p.m.
Software nodes that are children of another software node should be
unregistered before their parent. To allow easy unregistering of an array
of software_nodes ordered parent to child, reverse the order in which
this function unregisters software_nodes.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Daniel Scally <djrscally@gmail.com>
Changes since RFC v3:

	Switched this functionality from a new function to replacing
	the existing software_nodes_unregister_nodes()

 drivers/base/swnode.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)


diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index af7930b3679e..d39e1c76d98d 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -720,20 +720,25 @@  EXPORT_SYMBOL_GPL(software_node_register_nodes);
  * software_node_unregister_nodes - Unregister an array of software nodes
- * @nodes: Zero terminated array of software nodes to be unregistered
+ * @nodes: Zero terminated array of software nodes to be unregistered. If
+ * parent pointers are set up in any of the software nodes then the array
+ * MUST be ordered such that parents come before their children.
  * Unregister multiple software nodes at once.
- * NOTE: Be careful using this call if the nodes had parent pointers set up in
- * them before registering.  If so, it is wiser to remove the nodes
- * individually, in the correct order (child before parent) instead of relying
- * on the sequential order of the list of nodes in the array.
+ * NOTE: If you are uncertain whether the array is ordered such that
+ * parents will be unregistered before their children, it is wiser to
+ * remove the nodes individually, in the correct order (child before
+ * parent).
 void software_node_unregister_nodes(const struct software_node *nodes)
-	int i;
+	unsigned int i = 0;
+	while (nodes[i].name)
+		i++;
-	for (i = 0; nodes[i].name; i++)
+	while (i--)