stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] software node: implement software_node_unregister()
@ 2020-05-24 15:30 Greg Kroah-Hartman
  2020-05-24 16:43 ` Guenter Roeck
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Greg Kroah-Hartman @ 2020-05-24 15:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux, Greg Kroah-Hartman, Naresh Kamboju, kernel test robot,
	stable, Andy Shevchenko, Brendan Higgins, Dmitry Torokhov,
	Heikki Krogerus, Petr Mladek, Rafael J . Wysocki, Randy Dunlap,
	Rasmus Villemoes, Sakari Ailus, Sergey Senozhatsky,
	Steven Rostedt

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: f1ce39df508d ("lib/test_printf: Add tests for %pfw printk modifier")
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Reported-by: kernel test robot <rong.a.chen@intel.com>
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: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/base/swnode.c    | 27 +++++++++++++++++++++------
 include/linux/property.h |  1 +
 lib/test_printf.c        |  4 +++-
 3 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index de8d3543e8fe..770b1f47a625 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -712,17 +712,18 @@ EXPORT_SYMBOL_GPL(software_node_register_nodes);
  * @nodes: Zero terminated array of software nodes to be unregistered
  *
  * 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)
 {
-	struct swnode *swnode;
 	int i;
 
-	for (i = 0; nodes[i].name; i++) {
-		swnode = software_node_to_swnode(&nodes[i]);
-		if (swnode)
-			fwnode_remove_software_node(&swnode->fwnode);
-	}
+	for (i = 0; nodes[i].name; i++)
+		software_node_unregister(&nodes[i]);
 }
 EXPORT_SYMBOL_GPL(software_node_unregister_nodes);
 
@@ -741,6 +742,20 @@ int software_node_register(const struct software_node *node)
 }
 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 *
 fwnode_create_software_node(const struct property_entry *properties,
 			    const struct fwnode_handle *parent)
diff --git a/include/linux/property.h b/include/linux/property.h
index d86de017c689..0d4099b4ce1f 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -441,6 +441,7 @@ int software_node_register_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);
+void software_node_unregister(const struct software_node *node);
 
 int software_node_notify(struct device *dev, unsigned long action);
 
diff --git a/lib/test_printf.c b/lib/test_printf.c
index 6b1622f4d7c2..fc63b8959d42 100644
--- a/lib/test_printf.c
+++ b/lib/test_printf.c
@@ -637,7 +637,9 @@ static void __init fwnode_pointer(void)
 	test(second_name, "%pfwP", software_node_fwnode(&softnodes[1]));
 	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
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] software node: implement software_node_unregister()
  2020-05-24 15:30 [PATCH 1/2] software node: implement software_node_unregister() Greg Kroah-Hartman
@ 2020-05-24 16:43 ` Guenter Roeck
  2020-05-25  2:44   ` Randy Dunlap
  2020-05-25  7:59 ` Petr Mladek
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Guenter Roeck @ 2020-05-24 16:43 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-kernel
  Cc: Naresh Kamboju, kernel test robot, stable, Andy Shevchenko,
	Brendan Higgins, Dmitry Torokhov, Heikki Krogerus, Petr Mladek,
	Rafael J . Wysocki, Randy Dunlap, Rasmus Villemoes, Sakari Ailus,
	Sergey Senozhatsky, Steven Rostedt

On 5/24/20 8:30 AM, Greg Kroah-Hartman wrote:
> 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: f1ce39df508d ("lib/test_printf: Add tests for %pfw printk modifier")
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Reported-by: kernel test robot <rong.a.chen@intel.com>
> 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: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Petr Mladek <pmladek@suse.com>
> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> 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>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Both patches pass my boot tests on arm64 and arm64be (I didn't test any others).
So, FWIW,

Tested-by: Guenter Roeck <linux@roeck-us.net>

I wasn't sure it the two patches replace or fix commit 4ef12f719802 ("kobject:
Make sure the parent does not get released before its children"), so I tried
to re-apply 4ef12f719802 on top of the two patches. Unfortunately that still
results in crashes and UAF messages.

Guenter

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] software node: implement software_node_unregister()
  2020-05-24 16:43 ` Guenter Roeck
@ 2020-05-25  2:44   ` Randy Dunlap
  0 siblings, 0 replies; 7+ messages in thread
From: Randy Dunlap @ 2020-05-25  2:44 UTC (permalink / raw)
  To: Guenter Roeck, Greg Kroah-Hartman, linux-kernel
  Cc: Naresh Kamboju, kernel test robot, stable, Andy Shevchenko,
	Brendan Higgins, Dmitry Torokhov, Heikki Krogerus, Petr Mladek,
	Rafael J . Wysocki, Rasmus Villemoes, Sakari Ailus,
	Sergey Senozhatsky, Steven Rostedt

On 5/24/20 9:43 AM, Guenter Roeck wrote:
> On 5/24/20 8:30 AM, Greg Kroah-Hartman wrote:
>> 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: f1ce39df508d ("lib/test_printf: Add tests for %pfw printk modifier")
>> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
>> Reported-by: kernel test robot <rong.a.chen@intel.com>
>> 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: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>> Cc: Petr Mladek <pmladek@suse.com>
>> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>> Cc: Randy Dunlap <rdunlap@infradead.org>
>> 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>
>> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> Both patches pass my boot tests on arm64 and arm64be (I didn't test any others).
> So, FWIW,
> 
> Tested-by: Guenter Roeck <linux@roeck-us.net>
> 
> I wasn't sure it the two patches replace or fix commit 4ef12f719802 ("kobject:
> Make sure the parent does not get released before its children"), so I tried
> to re-apply 4ef12f719802 on top of the two patches. Unfortunately that still
> results in crashes and UAF messages.

Yes, that kobject patch has been reverted:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e6764aa0e5530066dd969eccea2a1a7d177859a8

and these 2 patches are to be used instead.

thanks.
-- 
~Randy


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] software node: implement software_node_unregister()
  2020-05-24 15:30 [PATCH 1/2] software node: implement software_node_unregister() Greg Kroah-Hartman
  2020-05-24 16:43 ` Guenter Roeck
@ 2020-05-25  7:59 ` Petr Mladek
  2020-05-25 11:24 ` Heikki Krogerus
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Petr Mladek @ 2020-05-25  7:59 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, linux, Naresh Kamboju, kernel test robot, stable,
	Andy Shevchenko, Brendan Higgins, Dmitry Torokhov,
	Heikki Krogerus, Rafael J . Wysocki, Randy Dunlap,
	Rasmus Villemoes, Sakari Ailus, Sergey Senozhatsky,
	Steven Rostedt

On Sun 2020-05-24 17:30:40, Greg Kroah-Hartman wrote:
> 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: f1ce39df508d ("lib/test_printf: Add tests for %pfw printk modifier")
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Reported-by: kernel test robot <rong.a.chen@intel.com>
> 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: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Petr Mladek <pmladek@suse.com>
> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> 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>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

I could confirm that this fixed lib/test_printf.c. The patch looks reasonable.

Tested-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] software node: implement software_node_unregister()
  2020-05-24 15:30 [PATCH 1/2] software node: implement software_node_unregister() Greg Kroah-Hartman
  2020-05-24 16:43 ` Guenter Roeck
  2020-05-25  7:59 ` Petr Mladek
@ 2020-05-25 11:24 ` Heikki Krogerus
  2020-05-26  0:12 ` Randy Dunlap
  2020-05-28 20:25 ` Brendan Higgins
  4 siblings, 0 replies; 7+ messages in thread
From: Heikki Krogerus @ 2020-05-25 11:24 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, linux, Naresh Kamboju, kernel test robot, stable,
	Andy Shevchenko, Brendan Higgins, Dmitry Torokhov, Petr Mladek,
	Rafael J . Wysocki, Randy Dunlap, Rasmus Villemoes, Sakari Ailus,
	Sergey Senozhatsky, Steven Rostedt

On Sun, May 24, 2020 at 05:30:40PM +0200, Greg Kroah-Hartman wrote:
> 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: f1ce39df508d ("lib/test_printf: Add tests for %pfw printk modifier")
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Reported-by: kernel test robot <rong.a.chen@intel.com>
> 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: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Petr Mladek <pmladek@suse.com>
> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> 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>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

FWIW:

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/base/swnode.c    | 27 +++++++++++++++++++++------
>  include/linux/property.h |  1 +
>  lib/test_printf.c        |  4 +++-
>  3 files changed, 25 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
> index de8d3543e8fe..770b1f47a625 100644
> --- a/drivers/base/swnode.c
> +++ b/drivers/base/swnode.c
> @@ -712,17 +712,18 @@ EXPORT_SYMBOL_GPL(software_node_register_nodes);
>   * @nodes: Zero terminated array of software nodes to be unregistered
>   *
>   * 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)
>  {
> -	struct swnode *swnode;
>  	int i;
>  
> -	for (i = 0; nodes[i].name; i++) {
> -		swnode = software_node_to_swnode(&nodes[i]);
> -		if (swnode)
> -			fwnode_remove_software_node(&swnode->fwnode);
> -	}
> +	for (i = 0; nodes[i].name; i++)
> +		software_node_unregister(&nodes[i]);
>  }
>  EXPORT_SYMBOL_GPL(software_node_unregister_nodes);
>  
> @@ -741,6 +742,20 @@ int software_node_register(const struct software_node *node)
>  }
>  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 *
>  fwnode_create_software_node(const struct property_entry *properties,
>  			    const struct fwnode_handle *parent)
> diff --git a/include/linux/property.h b/include/linux/property.h
> index d86de017c689..0d4099b4ce1f 100644
> --- a/include/linux/property.h
> +++ b/include/linux/property.h
> @@ -441,6 +441,7 @@ int software_node_register_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);
> +void software_node_unregister(const struct software_node *node);
>  
>  int software_node_notify(struct device *dev, unsigned long action);
>  
> diff --git a/lib/test_printf.c b/lib/test_printf.c
> index 6b1622f4d7c2..fc63b8959d42 100644
> --- a/lib/test_printf.c
> +++ b/lib/test_printf.c
> @@ -637,7 +637,9 @@ static void __init fwnode_pointer(void)
>  	test(second_name, "%pfwP", software_node_fwnode(&softnodes[1]));
>  	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
> -- 
> 2.26.2

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] software node: implement software_node_unregister()
  2020-05-24 15:30 [PATCH 1/2] software node: implement software_node_unregister() Greg Kroah-Hartman
                   ` (2 preceding siblings ...)
  2020-05-25 11:24 ` Heikki Krogerus
@ 2020-05-26  0:12 ` Randy Dunlap
  2020-05-28 20:25 ` Brendan Higgins
  4 siblings, 0 replies; 7+ messages in thread
From: Randy Dunlap @ 2020-05-26  0:12 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-kernel
  Cc: linux, Naresh Kamboju, kernel test robot, stable,
	Andy Shevchenko, Brendan Higgins, Dmitry Torokhov,
	Heikki Krogerus, Petr Mladek, Rafael J . Wysocki,
	Rasmus Villemoes, Sakari Ailus, Sergey Senozhatsky,
	Steven Rostedt

On 5/24/20 8:30 AM, Greg Kroah-Hartman wrote:
> 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: f1ce39df508d ("lib/test_printf: Add tests for %pfw printk modifier")
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Reported-by: kernel test robot <rong.a.chen@intel.com>
> 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: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Petr Mladek <pmladek@suse.com>
> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> 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>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Reported-by: Randy Dunlap <rdunlap@infradead.org>
Acked-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org>

thanks.

> ---
>  drivers/base/swnode.c    | 27 +++++++++++++++++++++------
>  include/linux/property.h |  1 +
>  lib/test_printf.c        |  4 +++-
>  3 files changed, 25 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
> index de8d3543e8fe..770b1f47a625 100644
> --- a/drivers/base/swnode.c
> +++ b/drivers/base/swnode.c
> @@ -712,17 +712,18 @@ EXPORT_SYMBOL_GPL(software_node_register_nodes);
>   * @nodes: Zero terminated array of software nodes to be unregistered
>   *
>   * 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)
>  {
> -	struct swnode *swnode;
>  	int i;
>  
> -	for (i = 0; nodes[i].name; i++) {
> -		swnode = software_node_to_swnode(&nodes[i]);
> -		if (swnode)
> -			fwnode_remove_software_node(&swnode->fwnode);
> -	}
> +	for (i = 0; nodes[i].name; i++)
> +		software_node_unregister(&nodes[i]);
>  }
>  EXPORT_SYMBOL_GPL(software_node_unregister_nodes);
>  
> @@ -741,6 +742,20 @@ int software_node_register(const struct software_node *node)
>  }
>  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 *
>  fwnode_create_software_node(const struct property_entry *properties,
>  			    const struct fwnode_handle *parent)
> diff --git a/include/linux/property.h b/include/linux/property.h
> index d86de017c689..0d4099b4ce1f 100644
> --- a/include/linux/property.h
> +++ b/include/linux/property.h
> @@ -441,6 +441,7 @@ int software_node_register_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);
> +void software_node_unregister(const struct software_node *node);
>  
>  int software_node_notify(struct device *dev, unsigned long action);
>  
> diff --git a/lib/test_printf.c b/lib/test_printf.c
> index 6b1622f4d7c2..fc63b8959d42 100644
> --- a/lib/test_printf.c
> +++ b/lib/test_printf.c
> @@ -637,7 +637,9 @@ static void __init fwnode_pointer(void)
>  	test(second_name, "%pfwP", software_node_fwnode(&softnodes[1]));
>  	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
> 


-- 
~Randy

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] software node: implement software_node_unregister()
  2020-05-24 15:30 [PATCH 1/2] software node: implement software_node_unregister() Greg Kroah-Hartman
                   ` (3 preceding siblings ...)
  2020-05-26  0:12 ` Randy Dunlap
@ 2020-05-28 20:25 ` Brendan Higgins
  4 siblings, 0 replies; 7+ messages in thread
From: Brendan Higgins @ 2020-05-28 20:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linux Kernel Mailing List, Guenter Roeck, Naresh Kamboju,
	kernel test robot, stable, Andy Shevchenko, Dmitry Torokhov,
	Heikki Krogerus, Petr Mladek, Rafael J . Wysocki, Randy Dunlap,
	Rasmus Villemoes, Sakari Ailus, Sergey Senozhatsky,
	Steven Rostedt

On Sun, May 24, 2020 at 8:31 AM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> 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: f1ce39df508d ("lib/test_printf: Add tests for %pfw printk modifier")
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Reported-by: kernel test robot <rong.a.chen@intel.com>
> 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: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Petr Mladek <pmladek@suse.com>
> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> 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>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Sorry, I was on vacation.

Seems like this has already been sufficiently reviewed and applied.
Nevertheless,

Tested-by: Brendan Higgins <brendanhiggins@google.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-05-28 20:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-24 15:30 [PATCH 1/2] software node: implement software_node_unregister() Greg Kroah-Hartman
2020-05-24 16:43 ` Guenter Roeck
2020-05-25  2:44   ` Randy Dunlap
2020-05-25  7:59 ` Petr Mladek
2020-05-25 11:24 ` Heikki Krogerus
2020-05-26  0:12 ` Randy Dunlap
2020-05-28 20:25 ` Brendan Higgins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).