devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next v2 0/3] of: Simplify with scoped for each OF child loop
@ 2024-08-26  6:24 Jinjie Ruan
  2024-08-26  6:24 ` [PATCH -next v2 1/3] of: overlay: " Jinjie Ruan
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jinjie Ruan @ 2024-08-26  6:24 UTC (permalink / raw)
  To: robh, saravanak, devicetree, linux-kernel, krzk; +Cc: ruanjinjie

Use for_each_child_of_node_scoped() to simplify code.

Changes in v2:
- Merge them into one patchset as Krzysztof suggested.

Jinjie Ruan (3):
  of: overlay: Simplify with scoped for each OF child loop
  of/platform: Simplify with scoped for each OF child
  of: resolver: Simplify with scoped for each OF child loop

 drivers/of/overlay.c  | 12 +++---------
 drivers/of/platform.c | 14 ++++----------
 drivers/of/resolver.c | 12 ++++--------
 3 files changed, 11 insertions(+), 27 deletions(-)

-- 
2.34.1


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

* [PATCH -next v2 1/3] of: overlay: Simplify with scoped for each OF child loop
  2024-08-26  6:24 [PATCH -next v2 0/3] of: Simplify with scoped for each OF child loop Jinjie Ruan
@ 2024-08-26  6:24 ` Jinjie Ruan
  2024-08-26  6:24 ` [PATCH -next v2 2/3] of/platform: Simplify with scoped for each OF child Jinjie Ruan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Jinjie Ruan @ 2024-08-26  6:24 UTC (permalink / raw)
  To: robh, saravanak, devicetree, linux-kernel, krzk; +Cc: ruanjinjie

Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 drivers/of/overlay.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 4d861a75d694..cbdecccca097 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -472,7 +472,6 @@ static int add_changeset_node(struct overlay_changeset *ovcs,
 static int build_changeset_next_level(struct overlay_changeset *ovcs,
 		struct target *target, const struct device_node *overlay_node)
 {
-	struct device_node *child;
 	struct property *prop;
 	int ret;
 
@@ -485,12 +484,11 @@ static int build_changeset_next_level(struct overlay_changeset *ovcs,
 		}
 	}
 
-	for_each_child_of_node(overlay_node, child) {
+	for_each_child_of_node_scoped(overlay_node, child) {
 		ret = add_changeset_node(ovcs, target, child);
 		if (ret) {
 			pr_debug("Failed to apply node @%pOF/%pOFn, err=%d\n",
 				 target->np, child, ret);
-			of_node_put(child);
 			return ret;
 		}
 	}
@@ -1078,16 +1076,12 @@ EXPORT_SYMBOL_GPL(of_overlay_fdt_apply);
  */
 static int find_node(struct device_node *tree, struct device_node *np)
 {
-	struct device_node *child;
-
 	if (tree == np)
 		return 1;
 
-	for_each_child_of_node(tree, child) {
-		if (find_node(child, np)) {
-			of_node_put(child);
+	for_each_child_of_node_scoped(tree, child) {
+		if (find_node(child, np))
 			return 1;
-		}
 	}
 
 	return 0;
-- 
2.34.1


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

* [PATCH -next v2 2/3] of/platform: Simplify with scoped for each OF child
  2024-08-26  6:24 [PATCH -next v2 0/3] of: Simplify with scoped for each OF child loop Jinjie Ruan
  2024-08-26  6:24 ` [PATCH -next v2 1/3] of: overlay: " Jinjie Ruan
@ 2024-08-26  6:24 ` Jinjie Ruan
  2024-08-26  6:24 ` [PATCH -next v2 3/3] of: resolver: Simplify with scoped for each OF child loop Jinjie Ruan
  2024-08-26 16:12 ` [PATCH -next v2 0/3] of: " Rob Herring
  3 siblings, 0 replies; 5+ messages in thread
From: Jinjie Ruan @ 2024-08-26  6:24 UTC (permalink / raw)
  To: robh, saravanak, devicetree, linux-kernel, krzk; +Cc: ruanjinjie

Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 drivers/of/platform.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 86be4dfb9323..ebc8f0359a95 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -338,7 +338,6 @@ static int of_platform_bus_create(struct device_node *bus,
 				  struct device *parent, bool strict)
 {
 	const struct of_dev_auxdata *auxdata;
-	struct device_node *child;
 	struct platform_device *dev;
 	const char *bus_id = NULL;
 	void *platform_data = NULL;
@@ -382,13 +381,11 @@ static int of_platform_bus_create(struct device_node *bus,
 	if (!dev || !of_match_node(matches, bus))
 		return 0;
 
-	for_each_child_of_node(bus, child) {
+	for_each_child_of_node_scoped(bus, child) {
 		pr_debug("   create child: %pOF\n", child);
 		rc = of_platform_bus_create(child, matches, lookup, &dev->dev, strict);
-		if (rc) {
-			of_node_put(child);
+		if (rc)
 			break;
-		}
 	}
 	of_node_set_flag(bus, OF_POPULATED_BUS);
 	return rc;
@@ -459,7 +456,6 @@ int of_platform_populate(struct device_node *root,
 			const struct of_dev_auxdata *lookup,
 			struct device *parent)
 {
-	struct device_node *child;
 	int rc = 0;
 
 	root = root ? of_node_get(root) : of_find_node_by_path("/");
@@ -470,12 +466,10 @@ int of_platform_populate(struct device_node *root,
 	pr_debug(" starting at: %pOF\n", root);
 
 	device_links_supplier_sync_state_pause();
-	for_each_child_of_node(root, child) {
+	for_each_child_of_node_scoped(root, child) {
 		rc = of_platform_bus_create(child, matches, lookup, parent, true);
-		if (rc) {
-			of_node_put(child);
+		if (rc)
 			break;
-		}
 	}
 	device_links_supplier_sync_state_resume();
 
-- 
2.34.1


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

* [PATCH -next v2 3/3] of: resolver: Simplify with scoped for each OF child loop
  2024-08-26  6:24 [PATCH -next v2 0/3] of: Simplify with scoped for each OF child loop Jinjie Ruan
  2024-08-26  6:24 ` [PATCH -next v2 1/3] of: overlay: " Jinjie Ruan
  2024-08-26  6:24 ` [PATCH -next v2 2/3] of/platform: Simplify with scoped for each OF child Jinjie Ruan
@ 2024-08-26  6:24 ` Jinjie Ruan
  2024-08-26 16:12 ` [PATCH -next v2 0/3] of: " Rob Herring
  3 siblings, 0 replies; 5+ messages in thread
From: Jinjie Ruan @ 2024-08-26  6:24 UTC (permalink / raw)
  To: robh, saravanak, devicetree, linux-kernel, krzk; +Cc: ruanjinjie

Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 drivers/of/resolver.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c
index 2780928764a4..5cf96776dd7d 100644
--- a/drivers/of/resolver.c
+++ b/drivers/of/resolver.c
@@ -150,7 +150,7 @@ static int node_name_cmp(const struct device_node *dn1,
 static int adjust_local_phandle_references(struct device_node *local_fixups,
 		struct device_node *overlay, int phandle_delta)
 {
-	struct device_node *child, *overlay_child;
+	struct device_node *overlay_child;
 	struct property *prop_fix, *prop;
 	int err, i, count;
 	unsigned int off;
@@ -194,7 +194,7 @@ static int adjust_local_phandle_references(struct device_node *local_fixups,
 	 * The roots of the subtrees are the overlay's __local_fixups__ node
 	 * and the overlay's root node.
 	 */
-	for_each_child_of_node(local_fixups, child) {
+	for_each_child_of_node_scoped(local_fixups, child) {
 
 		for_each_child_of_node(overlay, overlay_child)
 			if (!node_name_cmp(child, overlay_child)) {
@@ -202,17 +202,13 @@ static int adjust_local_phandle_references(struct device_node *local_fixups,
 				break;
 			}
 
-		if (!overlay_child) {
-			of_node_put(child);
+		if (!overlay_child)
 			return -EINVAL;
-		}
 
 		err = adjust_local_phandle_references(child, overlay_child,
 				phandle_delta);
-		if (err) {
-			of_node_put(child);
+		if (err)
 			return err;
-		}
 	}
 
 	return 0;
-- 
2.34.1


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

* Re: [PATCH -next v2 0/3] of: Simplify with scoped for each OF child loop
  2024-08-26  6:24 [PATCH -next v2 0/3] of: Simplify with scoped for each OF child loop Jinjie Ruan
                   ` (2 preceding siblings ...)
  2024-08-26  6:24 ` [PATCH -next v2 3/3] of: resolver: Simplify with scoped for each OF child loop Jinjie Ruan
@ 2024-08-26 16:12 ` Rob Herring
  3 siblings, 0 replies; 5+ messages in thread
From: Rob Herring @ 2024-08-26 16:12 UTC (permalink / raw)
  To: Jinjie Ruan; +Cc: saravanak, devicetree, linux-kernel, krzk

On Mon, Aug 26, 2024 at 02:24:05PM +0800, Jinjie Ruan wrote:
> Use for_each_child_of_node_scoped() to simplify code.
> 
> Changes in v2:
> - Merge them into one patchset as Krzysztof suggested.
> 
> Jinjie Ruan (3):
>   of: overlay: Simplify with scoped for each OF child loop
>   of/platform: Simplify with scoped for each OF child
>   of: resolver: Simplify with scoped for each OF child loop

Applied, thanks!

Rob

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

end of thread, other threads:[~2024-08-26 16:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-26  6:24 [PATCH -next v2 0/3] of: Simplify with scoped for each OF child loop Jinjie Ruan
2024-08-26  6:24 ` [PATCH -next v2 1/3] of: overlay: " Jinjie Ruan
2024-08-26  6:24 ` [PATCH -next v2 2/3] of/platform: Simplify with scoped for each OF child Jinjie Ruan
2024-08-26  6:24 ` [PATCH -next v2 3/3] of: resolver: Simplify with scoped for each OF child loop Jinjie Ruan
2024-08-26 16:12 ` [PATCH -next v2 0/3] of: " Rob Herring

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