Skip to contentSkip to conversation

software node: Two fixes

PATCH In review Heikki Krogerus 3 participants 11 messages Mar 1, 2021 – Mar 11, 2021

Subsystems (3)
lore
Share & tools
lore

Heikki Krogerus

author reviewer
#0 lore raw

cover software node: Two fixes

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(-)
Signature · 1 line
2.30.1
author reviewer
#1 lore raw

PATCH 1/2 software node: Fix node registration

Software node can not be registered before its parent.

Fixes 80488a6b1d3c ("software node: Add support for static node descriptors")
---
 drivers/base/swnode.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/base/swnode.c +3 -0
index 37179a8b1ceba..74db8c971db74 100644
@@ -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);
Signature · 1 line
2.30.1
reviewer Reviewed-by Tested-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] software node: Fix node registration

Quoted 1 line · Heikki Krogerus

Software node can not be registered before its parent.

(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!

Quoted 24 lines
Fixes 80488a6b1d3c ("software node: Add support for static node descriptors")
---
 drivers/base/swnode.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/base/swnode.c +3 -0
index 37179a8b1ceba..74db8c971db74 100644
@@ -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);
Signature · 1 line
2.30.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#3 lore raw

PATCH 2/2 software node: Fix device_add_software_node()

In reply to Heikki Krogerus

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()")
---
 drivers/base/swnode.c    | 26 +++++++++++++++++---------
 include/linux/property.h |  2 +-
 2 files changed, 18 insertions(+), 10 deletions(-)
drivers/base/swnode.c +17 -9
index 74db8c971db74..fa3719ef80e4d 100644
@@ -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;
 }
include/linux/property.h +1 -1
index dafccfce02624..dd4687b562393 100644
@@ -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,
Signature · 1 line
2.30.1
reviewer Reviewed-by Tested-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] software node: Fix device_add_software_node()

Quoted 10 lines · Heikki Krogerus

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.

(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!

Quoted 70 lines
Fixes e68d0119e328 ("software node: Introduce device_add_software_node()")
---
 drivers/base/swnode.c    | 26 +++++++++++++++++---------
 include/linux/property.h |  2 +-
 2 files changed, 18 insertions(+), 10 deletions(-)
drivers/base/swnode.c +17 -9
index 74db8c971db74..fa3719ef80e4d 100644
@@ -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;
 }
include/linux/property.h +1 -1
index dafccfce02624..dd4687b562393 100644
@@ -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,
Signature · 1 line
2.30.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
In reply to Heikki Krogerus
Quoted 3 lines · Heikki Krogerus

Hi,

The second one only affects 5.12-rc1.

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

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Heikki Krogerus

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?

author reviewer
#7 lore raw
Quoted 11 lines · Rafael J. Wysocki
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Heikki Krogerus

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,

Signature · 1 line
heikki
#8 lore raw
Quoted 8 lines · Heikki Krogerus
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Andy Shevchenko
Quoted 2 lines · Heikki Krogerus

Hi,

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

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.

#9 lore raw
Quoted 13 lines · Rafael J. Wysocki
Quoted 10 lines · Heikki Krogerus
Quoted 8 lines · Rafael J. Wysocki
Quoted 6 lines · Andy Shevchenko
Quoted 3 lines · Heikki Krogerus

Hi,

The second one only affects 5.12-rc1.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

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.

author reviewer
#10 lore raw
Quoted 18 lines · Rafael J. Wysocki
Quoted 17 lines · Rafael J. Wysocki
Quoted 14 lines · Heikki Krogerus
Quoted 11 lines · Rafael J. Wysocki
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Heikki Krogerus

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?

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

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,

Signature · 1 line
heikki