linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] software node: Two fixes
@ 2021-03-01 14:30 Heikki Krogerus
  2021-03-01 14:30 ` [PATCH 1/2] software node: Fix node registration Heikki Krogerus
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Heikki Krogerus @ 2021-03-01 14:30 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Rafael J. Wysocki, Andy Shevchenko, linux-kernel

Hi,

The second one only affects 5.12-rc1.


Heikki Krogerus (2):
  software node: Fix node registration
  software node: Fix device_add_software_node()

 drivers/base/swnode.c    | 29 ++++++++++++++++++++---------
 include/linux/property.h |  2 +-
 2 files changed, 21 insertions(+), 10 deletions(-)

-- 
2.30.1


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

* [PATCH 1/2] software node: Fix node registration
  2021-03-01 14:30 [PATCH 0/2] software node: Two fixes Heikki Krogerus
@ 2021-03-01 14:30 ` Heikki Krogerus
  2021-03-01 15:10   ` Andy Shevchenko
  2021-03-01 14:30 ` [PATCH 2/2] software node: Fix device_add_software_node() Heikki Krogerus
  2021-03-09 10:51 ` [PATCH 0/2] software node: Two fixes Andy Shevchenko
  2 siblings, 1 reply; 11+ messages in thread
From: Heikki Krogerus @ 2021-03-01 14:30 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Rafael J. Wysocki, Andy Shevchenko, linux-kernel, stable

Software node can not be registered before its parent.

Fixes: 80488a6b1d3c ("software node: Add support for static node descriptors")
Cc: stable@vger.kernel.org
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/base/swnode.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 37179a8b1ceba..74db8c971db74 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -938,6 +938,9 @@ int software_node_register(const struct software_node *node)
 	if (software_node_to_swnode(node))
 		return -EEXIST;
 
+	if (node->parent && !parent)
+		return -EINVAL;
+
 	return PTR_ERR_OR_ZERO(swnode_register(node, parent, 0));
 }
 EXPORT_SYMBOL_GPL(software_node_register);
-- 
2.30.1


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

* [PATCH 2/2] software node: Fix device_add_software_node()
  2021-03-01 14:30 [PATCH 0/2] software node: Two fixes Heikki Krogerus
  2021-03-01 14:30 ` [PATCH 1/2] software node: Fix node registration Heikki Krogerus
@ 2021-03-01 14:30 ` Heikki Krogerus
  2021-03-01 15:11   ` Andy Shevchenko
  2021-03-09 10:51 ` [PATCH 0/2] software node: Two fixes Andy Shevchenko
  2 siblings, 1 reply; 11+ messages in thread
From: Heikki Krogerus @ 2021-03-01 14:30 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Rafael J. Wysocki, Andy Shevchenko, linux-kernel

The function device_add_software_node() was meant to
register the node supplied to it, but only if that node
wasn't already registered. Right now the function attempts
to always register the node. That will cause a failure with
nodes that are already registered.

Fixing that by incrementing the reference count of the nodes
that have already been registered, and only registering the
new nodes. Also, clarifying the behaviour in the function
documentation.

Fixes: e68d0119e328 ("software node: Introduce device_add_software_node()")
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/base/swnode.c    | 26 +++++++++++++++++---------
 include/linux/property.h |  2 +-
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 74db8c971db74..fa3719ef80e4d 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -1005,25 +1005,33 @@ EXPORT_SYMBOL_GPL(fwnode_remove_software_node);
 /**
  * device_add_software_node - Assign software node to a device
  * @dev: The device the software node is meant for.
- * @swnode: The software node.
+ * @node: The software node.
  *
- * This function will register @swnode and make it the secondary firmware node
- * pointer of @dev. If @dev has no primary node, then @swnode will become the primary
- * node.
+ * This function will make @node the secondary firmware node pointer of @dev. If
+ * @dev has no primary node, then @node will become the primary node. The
+ * function will register @node automatically if it wasn't already registered.
  */
-int device_add_software_node(struct device *dev, const struct software_node *swnode)
+int device_add_software_node(struct device *dev, const struct software_node *node)
 {
+	struct swnode *swnode;
 	int ret;
 
 	/* Only one software node per device. */
 	if (dev_to_swnode(dev))
 		return -EBUSY;
 
-	ret = software_node_register(swnode);
-	if (ret)
-		return ret;
+	swnode = software_node_to_swnode(node);
+	if (swnode) {
+		kobject_get(&swnode->kobj);
+	} else {
+		ret = software_node_register(node);
+		if (ret)
+			return ret;
+
+		swnode = software_node_to_swnode(node);
+	}
 
-	set_secondary_fwnode(dev, software_node_fwnode(swnode));
+	set_secondary_fwnode(dev, &swnode->fwnode);
 
 	return 0;
 }
diff --git a/include/linux/property.h b/include/linux/property.h
index dafccfce02624..dd4687b562393 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -488,7 +488,7 @@ fwnode_create_software_node(const struct property_entry *properties,
 			    const struct fwnode_handle *parent);
 void fwnode_remove_software_node(struct fwnode_handle *fwnode);
 
-int device_add_software_node(struct device *dev, const struct software_node *swnode);
+int device_add_software_node(struct device *dev, const struct software_node *node);
 void device_remove_software_node(struct device *dev);
 
 int device_create_managed_software_node(struct device *dev,
-- 
2.30.1


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

* Re: [PATCH 1/2] software node: Fix node registration
  2021-03-01 14:30 ` [PATCH 1/2] software node: Fix node registration Heikki Krogerus
@ 2021-03-01 15:10   ` Andy Shevchenko
  0 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2021-03-01 15:10 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: Greg Kroah-Hartman, Rafael J. Wysocki, linux-kernel, stable

On Mon, Mar 01, 2021 at 05:30:11PM +0300, Heikki Krogerus wrote:
> Software node can not be registered before its parent.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

(On Intel Galileo Gen 2 with some custom patches to convert gpio-dwapb et al.
 to use swnodes. Those patches a subject to further submission.)

Thanks!

> Fixes: 80488a6b1d3c ("software node: Add support for static node descriptors")
> Cc: stable@vger.kernel.org
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
>  drivers/base/swnode.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
> index 37179a8b1ceba..74db8c971db74 100644
> --- a/drivers/base/swnode.c
> +++ b/drivers/base/swnode.c
> @@ -938,6 +938,9 @@ int software_node_register(const struct software_node *node)
>  	if (software_node_to_swnode(node))
>  		return -EEXIST;
>  
> +	if (node->parent && !parent)
> +		return -EINVAL;
> +
>  	return PTR_ERR_OR_ZERO(swnode_register(node, parent, 0));
>  }
>  EXPORT_SYMBOL_GPL(software_node_register);
> -- 
> 2.30.1
> 

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 2/2] software node: Fix device_add_software_node()
  2021-03-01 14:30 ` [PATCH 2/2] software node: Fix device_add_software_node() Heikki Krogerus
@ 2021-03-01 15:11   ` Andy Shevchenko
  0 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2021-03-01 15:11 UTC (permalink / raw)
  To: Heikki Krogerus; +Cc: Greg Kroah-Hartman, Rafael J. Wysocki, linux-kernel

On Mon, Mar 01, 2021 at 05:30:12PM +0300, Heikki Krogerus wrote:
> The function device_add_software_node() was meant to
> register the node supplied to it, but only if that node
> wasn't already registered. Right now the function attempts
> to always register the node. That will cause a failure with
> nodes that are already registered.
> 
> Fixing that by incrementing the reference count of the nodes
> that have already been registered, and only registering the
> new nodes. Also, clarifying the behaviour in the function
> documentation.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

(On Intel Galileo Gen 2 with some custom patches to convert gpio-dwapb et al.
  to use swnodes. Those patches a subject to further submission.)

Thanks!

> Fixes: e68d0119e328 ("software node: Introduce device_add_software_node()")
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
>  drivers/base/swnode.c    | 26 +++++++++++++++++---------
>  include/linux/property.h |  2 +-
>  2 files changed, 18 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
> index 74db8c971db74..fa3719ef80e4d 100644
> --- a/drivers/base/swnode.c
> +++ b/drivers/base/swnode.c
> @@ -1005,25 +1005,33 @@ EXPORT_SYMBOL_GPL(fwnode_remove_software_node);
>  /**
>   * device_add_software_node - Assign software node to a device
>   * @dev: The device the software node is meant for.
> - * @swnode: The software node.
> + * @node: The software node.
>   *
> - * This function will register @swnode and make it the secondary firmware node
> - * pointer of @dev. If @dev has no primary node, then @swnode will become the primary
> - * node.
> + * This function will make @node the secondary firmware node pointer of @dev. If
> + * @dev has no primary node, then @node will become the primary node. The
> + * function will register @node automatically if it wasn't already registered.
>   */
> -int device_add_software_node(struct device *dev, const struct software_node *swnode)
> +int device_add_software_node(struct device *dev, const struct software_node *node)
>  {
> +	struct swnode *swnode;
>  	int ret;
>  
>  	/* Only one software node per device. */
>  	if (dev_to_swnode(dev))
>  		return -EBUSY;
>  
> -	ret = software_node_register(swnode);
> -	if (ret)
> -		return ret;
> +	swnode = software_node_to_swnode(node);
> +	if (swnode) {
> +		kobject_get(&swnode->kobj);
> +	} else {
> +		ret = software_node_register(node);
> +		if (ret)
> +			return ret;
> +
> +		swnode = software_node_to_swnode(node);
> +	}
>  
> -	set_secondary_fwnode(dev, software_node_fwnode(swnode));
> +	set_secondary_fwnode(dev, &swnode->fwnode);
>  
>  	return 0;
>  }
> diff --git a/include/linux/property.h b/include/linux/property.h
> index dafccfce02624..dd4687b562393 100644
> --- a/include/linux/property.h
> +++ b/include/linux/property.h
> @@ -488,7 +488,7 @@ fwnode_create_software_node(const struct property_entry *properties,
>  			    const struct fwnode_handle *parent);
>  void fwnode_remove_software_node(struct fwnode_handle *fwnode);
>  
> -int device_add_software_node(struct device *dev, const struct software_node *swnode);
> +int device_add_software_node(struct device *dev, const struct software_node *node);
>  void device_remove_software_node(struct device *dev);
>  
>  int device_create_managed_software_node(struct device *dev,
> -- 
> 2.30.1
> 

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 0/2] software node: Two fixes
  2021-03-01 14:30 [PATCH 0/2] software node: Two fixes Heikki Krogerus
  2021-03-01 14:30 ` [PATCH 1/2] software node: Fix node registration Heikki Krogerus
  2021-03-01 14:30 ` [PATCH 2/2] software node: Fix device_add_software_node() Heikki Krogerus
@ 2021-03-09 10:51 ` Andy Shevchenko
  2021-03-09 13:51   ` Rafael J. Wysocki
  2 siblings, 1 reply; 11+ messages in thread
From: Andy Shevchenko @ 2021-03-09 10:51 UTC (permalink / raw)
  To: Heikki Krogerus; +Cc: Greg Kroah-Hartman, Rafael J. Wysocki, linux-kernel

On Mon, Mar 01, 2021 at 05:30:10PM +0300, Heikki Krogerus wrote:
> Hi,
> 
> The second one only affects 5.12-rc1.

Rafael, Greg, can this be applied for v5.12-rcX?

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 0/2] software node: Two fixes
  2021-03-09 10:51 ` [PATCH 0/2] software node: Two fixes Andy Shevchenko
@ 2021-03-09 13:51   ` Rafael J. Wysocki
  2021-03-10  7:36     ` Heikki Krogerus
  0 siblings, 1 reply; 11+ messages in thread
From: Rafael J. Wysocki @ 2021-03-09 13:51 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Heikki Krogerus, Greg Kroah-Hartman, Rafael J. Wysocki,
	Linux Kernel Mailing List

On Tue, Mar 9, 2021 at 11:51 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Mon, Mar 01, 2021 at 05:30:10PM +0300, Heikki Krogerus wrote:
> > Hi,
> >
> > The second one only affects 5.12-rc1.
>
> Rafael, Greg, can this be applied for v5.12-rcX?

Do you have a pointer to this?

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

* Re: [PATCH 0/2] software node: Two fixes
  2021-03-09 13:51   ` Rafael J. Wysocki
@ 2021-03-10  7:36     ` Heikki Krogerus
  2021-03-10 14:16       ` Rafael J. Wysocki
  0 siblings, 1 reply; 11+ messages in thread
From: Heikki Krogerus @ 2021-03-10  7:36 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Andy Shevchenko, Greg Kroah-Hartman, Linux Kernel Mailing List

On Tue, Mar 09, 2021 at 02:51:22PM +0100, Rafael J. Wysocki wrote:
> On Tue, Mar 9, 2021 at 11:51 AM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > On Mon, Mar 01, 2021 at 05:30:10PM +0300, Heikki Krogerus wrote:
> > > Hi,
> > >
> > > The second one only affects 5.12-rc1.
> >
> > Rafael, Greg, can this be applied for v5.12-rcX?
> 
> Do you have a pointer to this?

Pointer?

thanks,

-- 
heikki

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

* Re: [PATCH 0/2] software node: Two fixes
  2021-03-10  7:36     ` Heikki Krogerus
@ 2021-03-10 14:16       ` Rafael J. Wysocki
  2021-03-10 14:30         ` Rafael J. Wysocki
  0 siblings, 1 reply; 11+ messages in thread
From: Rafael J. Wysocki @ 2021-03-10 14:16 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: Rafael J. Wysocki, Andy Shevchenko, Greg Kroah-Hartman,
	Linux Kernel Mailing List

On Wed, Mar 10, 2021 at 8:36 AM Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
>
> On Tue, Mar 09, 2021 at 02:51:22PM +0100, Rafael J. Wysocki wrote:
> > On Tue, Mar 9, 2021 at 11:51 AM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > >
> > > On Mon, Mar 01, 2021 at 05:30:10PM +0300, Heikki Krogerus wrote:
> > > > Hi,
> > > >
> > > > The second one only affects 5.12-rc1.
> > >
> > > Rafael, Greg, can this be applied for v5.12-rcX?
> >
> > Do you have a pointer to this?
>
> Pointer?

Never mind, I'll pick them up from the archive.

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

* Re: [PATCH 0/2] software node: Two fixes
  2021-03-10 14:16       ` Rafael J. Wysocki
@ 2021-03-10 14:30         ` Rafael J. Wysocki
  2021-03-11  8:23           ` Heikki Krogerus
  0 siblings, 1 reply; 11+ messages in thread
From: Rafael J. Wysocki @ 2021-03-10 14:30 UTC (permalink / raw)
  To: Heikki Krogerus, Andy Shevchenko
  Cc: Greg Kroah-Hartman, Linux Kernel Mailing List

On Wed, Mar 10, 2021 at 3:16 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Wed, Mar 10, 2021 at 8:36 AM Heikki Krogerus
> <heikki.krogerus@linux.intel.com> wrote:
> >
> > On Tue, Mar 09, 2021 at 02:51:22PM +0100, Rafael J. Wysocki wrote:
> > > On Tue, Mar 9, 2021 at 11:51 AM Andy Shevchenko
> > > <andriy.shevchenko@linux.intel.com> wrote:
> > > >
> > > > On Mon, Mar 01, 2021 at 05:30:10PM +0300, Heikki Krogerus wrote:
> > > > > Hi,
> > > > >
> > > > > The second one only affects 5.12-rc1.
> > > >
> > > > Rafael, Greg, can this be applied for v5.12-rcX?
> > >
> > > Do you have a pointer to this?
> >
> > Pointer?
>
> Never mind, I'll pick them up from the archive.

Both [1-2/2] applied as 5.12-rc material now, thanks!

However, I would appreciate CCing swnode-related material to linux-acpi.

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

* Re: [PATCH 0/2] software node: Two fixes
  2021-03-10 14:30         ` Rafael J. Wysocki
@ 2021-03-11  8:23           ` Heikki Krogerus
  0 siblings, 0 replies; 11+ messages in thread
From: Heikki Krogerus @ 2021-03-11  8:23 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Andy Shevchenko, Greg Kroah-Hartman, Linux Kernel Mailing List

On Wed, Mar 10, 2021 at 03:30:09PM +0100, Rafael J. Wysocki wrote:
> On Wed, Mar 10, 2021 at 3:16 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
> >
> > On Wed, Mar 10, 2021 at 8:36 AM Heikki Krogerus
> > <heikki.krogerus@linux.intel.com> wrote:
> > >
> > > On Tue, Mar 09, 2021 at 02:51:22PM +0100, Rafael J. Wysocki wrote:
> > > > On Tue, Mar 9, 2021 at 11:51 AM Andy Shevchenko
> > > > <andriy.shevchenko@linux.intel.com> wrote:
> > > > >
> > > > > On Mon, Mar 01, 2021 at 05:30:10PM +0300, Heikki Krogerus wrote:
> > > > > > Hi,
> > > > > >
> > > > > > The second one only affects 5.12-rc1.
> > > > >
> > > > > Rafael, Greg, can this be applied for v5.12-rcX?
> > > >
> > > > Do you have a pointer to this?
> > >
> > > Pointer?
> >
> > Never mind, I'll pick them up from the archive.
> 
> Both [1-2/2] applied as 5.12-rc material now, thanks!
> 
> However, I would appreciate CCing swnode-related material to linux-acpi.

Sure think. Maybe it would be better to add an entry for the thing to
the MAINTAINERS file. That way we can make linux-acpi the ml for it. I
have half automated the preparation of patches and I rely on the
get_maintainer.pl script, so it would make at least my life a bit
easier :-).

I'll send you the patch. I'll make myself and Andy the reviewers.

thanks,

-- 
heikki

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

end of thread, other threads:[~2021-03-11  8:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-01 14:30 [PATCH 0/2] software node: Two fixes Heikki Krogerus
2021-03-01 14:30 ` [PATCH 1/2] software node: Fix node registration Heikki Krogerus
2021-03-01 15:10   ` Andy Shevchenko
2021-03-01 14:30 ` [PATCH 2/2] software node: Fix device_add_software_node() Heikki Krogerus
2021-03-01 15:11   ` Andy Shevchenko
2021-03-09 10:51 ` [PATCH 0/2] software node: Two fixes Andy Shevchenko
2021-03-09 13:51   ` Rafael J. Wysocki
2021-03-10  7:36     ` Heikki Krogerus
2021-03-10 14:16       ` Rafael J. Wysocki
2021-03-10 14:30         ` Rafael J. Wysocki
2021-03-11  8:23           ` Heikki Krogerus

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).