Commit 46d26819 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

software node: implement software_node_unregister()

Sometimes it is better to unregister individual nodes instead of trying
to do them all at once with software_node_unregister_nodes(), so create
software_node_unregister() so that you can unregister them one at a
time.

This is especially important when creating nodes in a hierarchy, with
parent -> children representations.  Children always need to be removed
before a parent is, as the swnode logic assumes this is going to be the
case.

Fix up the lib/test_printf.c fwnode_pointer() test which to use this new
function as it had the problem of tearing things down in the backwards
order.

Fixes: f1ce39df ("lib/test_printf: Add tests for %pfw printk modifier")
Cc: stable <stable@vger.kernel.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Brendan Higgins <brendanhiggins@google.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Reported-by: default avatarNaresh Kamboju <naresh.kamboju@linaro.org>
Reported-by: default avatarkernel test robot <rong.a.chen@intel.com>
Reported-by: default avatarRandy Dunlap <rdunlap@infradead.org>
Tested-by: default avatarPetr Mladek <pmladek@suse.com>
Tested-by: default avatarRandy Dunlap <rdunlap@infradead.org>
Tested-by: default avatarGuenter Roeck <linux@roeck-us.net>
Reviewed-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Acked-by: default avatarRandy Dunlap <rdunlap@infradead.org>
Link: https://lore.kernel.org/r/20200524153041.2361-1-gregkh@linuxfoundation.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0e5596c5
...@@ -712,17 +712,18 @@ EXPORT_SYMBOL_GPL(software_node_register_nodes); ...@@ -712,17 +712,18 @@ EXPORT_SYMBOL_GPL(software_node_register_nodes);
* @nodes: Zero terminated array of software nodes to be unregistered * @nodes: Zero terminated array of software nodes to be unregistered
* *
* Unregister multiple software nodes at once. * 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.
*/ */
void software_node_unregister_nodes(const struct software_node *nodes) void software_node_unregister_nodes(const struct software_node *nodes)
{ {
struct swnode *swnode;
int i; int i;
for (i = 0; nodes[i].name; i++) { for (i = 0; nodes[i].name; i++)
swnode = software_node_to_swnode(&nodes[i]); software_node_unregister(&nodes[i]);
if (swnode)
fwnode_remove_software_node(&swnode->fwnode);
}
} }
EXPORT_SYMBOL_GPL(software_node_unregister_nodes); EXPORT_SYMBOL_GPL(software_node_unregister_nodes);
...@@ -741,6 +742,20 @@ int software_node_register(const struct software_node *node) ...@@ -741,6 +742,20 @@ int software_node_register(const struct software_node *node)
} }
EXPORT_SYMBOL_GPL(software_node_register); EXPORT_SYMBOL_GPL(software_node_register);
/**
* software_node_unregister - Unregister static software node
* @node: The software node to be unregistered
*/
void software_node_unregister(const struct software_node *node)
{
struct swnode *swnode;
swnode = software_node_to_swnode(node);
if (swnode)
fwnode_remove_software_node(&swnode->fwnode);
}
EXPORT_SYMBOL_GPL(software_node_unregister);
struct fwnode_handle * struct fwnode_handle *
fwnode_create_software_node(const struct property_entry *properties, fwnode_create_software_node(const struct property_entry *properties,
const struct fwnode_handle *parent) const struct fwnode_handle *parent)
......
...@@ -441,6 +441,7 @@ int software_node_register_nodes(const struct software_node *nodes); ...@@ -441,6 +441,7 @@ int software_node_register_nodes(const struct software_node *nodes);
void software_node_unregister_nodes(const struct software_node *nodes); void software_node_unregister_nodes(const struct software_node *nodes);
int software_node_register(const struct software_node *node); int software_node_register(const struct software_node *node);
void software_node_unregister(const struct software_node *node);
int software_node_notify(struct device *dev, unsigned long action); int software_node_notify(struct device *dev, unsigned long action);
......
...@@ -637,7 +637,9 @@ static void __init fwnode_pointer(void) ...@@ -637,7 +637,9 @@ static void __init fwnode_pointer(void)
test(second_name, "%pfwP", software_node_fwnode(&softnodes[1])); test(second_name, "%pfwP", software_node_fwnode(&softnodes[1]));
test(third_name, "%pfwP", software_node_fwnode(&softnodes[2])); test(third_name, "%pfwP", software_node_fwnode(&softnodes[2]));
software_node_unregister_nodes(softnodes); software_node_unregister(&softnodes[2]);
software_node_unregister(&softnodes[1]);
software_node_unregister(&softnodes[0]);
} }
static void __init static void __init
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment