Skip to contentSkip to conversation

device property: Retrieve fwnode from of_node via accessor

PATCH Applied Andy Shevchenko 2 participants 4 messages May 10, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 device property: Retrieve fwnode from of_node via accessor

OF provides a specific accessor to retrieve fwnode handle. Use it instead of direct dereferencing.

---
 drivers/base/property.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/property.c +2 -2
index 1421e9548857..dd98759d688b 100644
@@ -21,7 +21,7 @@
 struct fwnode_handle *dev_fwnode(struct device *dev)
 {
 	return IS_ENABLED(CONFIG_OF) && dev->of_node ?
-		&dev->of_node->fwnode : dev->fwnode;
+		of_fwnode_handle(dev->of_node) : dev->fwnode;
 }
 EXPORT_SYMBOL_GPL(dev_fwnode);
 
@@ -763,7 +763,7 @@ struct fwnode_handle *device_get_next_child_node(struct device *dev,
 	struct fwnode_handle *fwnode = NULL, *next;
 
 	if (dev->of_node)
-		fwnode = &dev->of_node->fwnode;
+		fwnode = of_fwnode_handle(dev->of_node);
 	else if (adev)
 		fwnode = acpi_fwnode_handle(adev);
 
Signature · 1 line
2.31.1
#1 lore raw

PATCH 2/2 device property: Don't check for NULL twice in the loops

In fwnode_get_next_available_child_node() we check next_child for NULL twice. All the same in fwnode_get_next_parent_dev() we may avoid checking fwnode for NULL twice.

---
 drivers/base/property.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/base/property.c +6 -6
index dd98759d688b..62285f1b79e3 100644
@@ -632,9 +632,10 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode)
 	fwnode_handle_get(fwnode);
 	do {
 		fwnode = fwnode_get_next_parent(fwnode);
-		if (fwnode)
-			dev = get_dev_from_fwnode(fwnode);
-	} while (fwnode && !dev);
+		if (!fwnode)
+			break;
+		dev = get_dev_from_fwnode(fwnode);
+	} while (!dev);
 	fwnode_handle_put(fwnode);
 	return dev;
 }
@@ -742,10 +743,9 @@ fwnode_get_next_available_child_node(const struct fwnode_handle *fwnode,
 
 	do {
 		next_child = fwnode_get_next_child_node(fwnode, next_child);
-
-		if (!next_child || fwnode_device_is_available(next_child))
+		if (!next_child)
 			break;
-	} while (next_child);
+	} while (!fwnode_device_is_available(next_child));
 
 	return next_child;
 }
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH v1 2/2] device property: Don't check for NULL twice in the loops

Quoted 15 lines · Andy Shevchenko

In fwnode_get_next_available_child_node() we check next_child for NULL twice. All the same in fwnode_get_next_parent_dev() we may avoid checking fwnode for NULL twice.

---
 drivers/base/property.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/base/property.c +0 -0
index dd98759d688b..62285f1b79e3 100644

drivers/base/property.c struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode) · line 636

Quoted 8 lines
drivers/base/property.c +2 -3
@@ -632,9 +632,10 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode)
        fwnode_handle_get(fwnode);
        do {
                fwnode = fwnode_get_next_parent(fwnode);
-               if (fwnode)
-                       dev = get_dev_from_fwnode(fwnode);
-       } while (fwnode && !dev);
+               if (!fwnode)
+                       break;

I would return NULL from here right away.

drivers/base/property.c fwnode_get_next_available_child_node(const struct fwnode_handle *fwnode, · line 747

Quoted 13 lines
drivers/base/property.c +3 -2
+               dev = get_dev_from_fwnode(fwnode);
+       } while (!dev);
        fwnode_handle_put(fwnode);
        return dev;
 }
@@ -742,10 +743,9 @@ fwnode_get_next_available_child_node(const struct fwnode_handle *fwnode,
 
        do {
                next_child = fwnode_get_next_child_node(fwnode, next_child);
-
-               if (!next_child || fwnode_device_is_available(next_child))
+               if (!next_child)
                        break;

And from here too.

Quoted 8 lines
drivers/base/property.c +1 -2
-       } while (next_child);
+       } while (!fwnode_device_is_available(next_child));
 
        return next_child;
 }
--

2.31.1

maintainer Applied
#3 lore raw
In reply to Andy Shevchenko
Quoted 23 lines · Andy Shevchenko

OF provides a specific accessor to retrieve fwnode handle. Use it instead of direct dereferencing.

---
 drivers/base/property.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/property.c +1 -1
index 1421e9548857..dd98759d688b 100644
@@ -21,7 +21,7 @@
 struct fwnode_handle *dev_fwnode(struct device *dev)
 {
        return IS_ENABLED(CONFIG_OF) && dev->of_node ?
-               &dev->of_node->fwnode : dev->fwnode;
+               of_fwnode_handle(dev->of_node) : dev->fwnode;
 }
 EXPORT_SYMBOL_GPL(dev_fwnode);
 

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

Quoted 9 lines
drivers/base/property.c +1 -2
@@ -763,7 +763,7 @@ struct fwnode_handle *device_get_next_child_node(struct device *dev,
        struct fwnode_handle *fwnode = NULL, *next;
 
        if (dev->of_node)
-               fwnode = &dev->of_node->fwnode;
+               fwnode = of_fwnode_handle(dev->of_node);
        else if (adev)
                fwnode = acpi_fwnode_handle(adev);
 
--

Applied as 5.14 material, thanks!