Skip to contentSkip to conversation

drivers property: When no children in primary, try secondary

PATCH In review Andy Shevchenko 5 participants 5 messages May 20, 2020

Subsystems (2)
lore
Share & tools
lore

Andy Shevchenko

author reviewer
#0 lore raw

PATCH 1/1 drivers property: When no children in primary, try secondary

Software firmware nodes can provide a child node to its parent. Since software node can be secondary, we need a mechanism to access the children. The idea is to list children of the primary node first and when they are finished, continue with secondary node if available.

---
 drivers/base/property.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/base/property.c +11 -2
index 5f35c0ccf5e0..1e6d75e65938 100644
@@ -708,14 +708,23 @@ struct fwnode_handle *device_get_next_child_node(struct device *dev,
 						 struct fwnode_handle *child)
 {
 	struct acpi_device *adev = ACPI_COMPANION(dev);
-	struct fwnode_handle *fwnode = NULL;
+	struct fwnode_handle *fwnode = NULL, *next;
 
 	if (dev->of_node)
 		fwnode = &dev->of_node->fwnode;
 	else if (adev)
 		fwnode = acpi_fwnode_handle(adev);
 
-	return fwnode_get_next_child_node(fwnode, child);
+	/* Try to find a child in primary fwnode */
+	next = fwnode_get_next_child_node(fwnode, child);
+	if (next)
+		return next;
+
+	/* When no more children in primary, continue with secondary */
+	if (!IS_ERR_OR_NULL(fwnode->secondary))
+		next = fwnode_get_next_child_node(fwnode->secondary, child);
+
+	return next;
 }
 EXPORT_SYMBOL_GPL(device_get_next_child_node);
 
Signature · 1 line
2.26.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Andy Shevchenko

Software firmware nodes can provide a child node to its parent. Since software node can be secondary, we need a mechanism to access the children. The idea is to list children of the primary node first and when they are finished, continue with secondary node if available.

Makes sense.

Quoted 1 line

Greg, do you want me to apply it?

If you'd rather take it yourself, please feel free to add

Quoted 37 lines
---
 drivers/base/property.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/base/property.c +11 -3
index 5f35c0ccf5e0..1e6d75e65938 100644
@@ -708,14 +708,23 @@ struct fwnode_handle *device_get_next_child_node(struct device *dev,
                                                 struct fwnode_handle *child)
 {
        struct acpi_device *adev = ACPI_COMPANION(dev);
-       struct fwnode_handle *fwnode = NULL;
+       struct fwnode_handle *fwnode = NULL, *next;
 
        if (dev->of_node)
                fwnode = &dev->of_node->fwnode;
        else if (adev)
                fwnode = acpi_fwnode_handle(adev);
 
-       return fwnode_get_next_child_node(fwnode, child);
+       /* Try to find a child in primary fwnode */
+       next = fwnode_get_next_child_node(fwnode, child);
+       if (next)
+               return next;
+
+       /* When no more children in primary, continue with secondary */
+       if (!IS_ERR_OR_NULL(fwnode->secondary))
+               next = fwnode_get_next_child_node(fwnode->secondary, child);
+
+       return next;
 }
 EXPORT_SYMBOL_GPL(device_get_next_child_node);
 
--

2.26.2

reviewer Acked-by on v1 1/1
#3 lore raw
In reply to Andy Shevchenko

Thanks, Andy!

Quoted 6 lines · Andy Shevchenko

Software firmware nodes can provide a child node to its parent. Since software node can be secondary, we need a mechanism to access the children. The idea is to list children of the primary node first and when they are finished, continue with secondary node if available.

Signature · 1 line
Sakari Ailus
reviewer Reviewed-by on v1 1/1
#4 lore raw
In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

Software firmware nodes can provide a child node to its parent. Since software node can be secondary, we need a mechanism to access the children. The idea is to list children of the primary node first and when they are finished, continue with secondary node if available.

FWIW:

Quoted 23 lines
---
 drivers/base/property.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/base/property.c +3 -2
index 5f35c0ccf5e0..1e6d75e65938 100644
@@ -708,14 +708,23 @@ struct fwnode_handle *device_get_next_child_node(struct device *dev,
 						 struct fwnode_handle *child)
 {
 	struct acpi_device *adev = ACPI_COMPANION(dev);
-	struct fwnode_handle *fwnode = NULL;
+	struct fwnode_handle *fwnode = NULL, *next;
 
 	if (dev->of_node)
 		fwnode = &dev->of_node->fwnode;
 	else if (adev)
 		fwnode = acpi_fwnode_handle(adev);
 
-	return fwnode_get_next_child_node(fwnode, child);
+	/* Try to find a child in primary fwnode */
+	next = fwnode_get_next_child_node(fwnode, child);

drivers/base/property.c struct fwnode_handle *device_get_next_child_node(struct device *dev, · line 729

Quoted 10 lines
drivers/base/property.c +8 -0
+	if (next)
+		return next;
+
+	/* When no more children in primary, continue with secondary */
+	if (!IS_ERR_OR_NULL(fwnode->secondary))
+		next = fwnode_get_next_child_node(fwnode->secondary, child);
+
+	return next;
 }
 EXPORT_SYMBOL_GPL(device_get_next_child_node);

Thanks Andy,

Signature · 1 line
heikki
#2 lore raw
In reply to Rafael J. Wysocki
Quoted 10 lines · Rafael J. Wysocki
Quoted 5 lines · Andy Shevchenko

Software firmware nodes can provide a child node to its parent. Since software node can be secondary, we need a mechanism to access the children. The idea is to list children of the primary node first and when they are finished, continue with secondary node if available.

Makes sense.

Quoted 7 lines
Quoted 1 line

Greg, do you want me to apply it?

If you'd rather take it yourself, please feel free to add

I can take it, there's other driver core patches in my tree already :)

thanks,

greg k-h