diff mbox series

[v2,2/6] ASoC: aoa: Use helper function for_each_child_of_node_scoped()

Message ID 20250522050300.519244-3-aichao@kylinos.cn
State New
Headers show
Series Use helper function for_each_child_of_node_scoped() | expand

Commit Message

Ai Chao May 22, 2025, 5:02 a.m. UTC
The for_each_child_of_node_scoped() helper provides a scope-based
clean-up functionality to put the device_node automatically, and
as such, there is no need to call of_node_put() directly.

Thus, use this helper to simplify the code.

Signed-off-by: Ai Chao <aichao@kylinos.cn>
---
 sound/aoa/soundbus/i2sbus/core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Johannes Berg May 22, 2025, 10:04 a.m. UTC | #1
On Thu, 2025-05-22 at 13:02 +0800, Ai Chao wrote:
> The for_each_child_of_node_scoped() helper provides a scope-based
> clean-up functionality to put the device_node automatically, and
> as such, there is no need to call of_node_put() directly.
> 
> Thus, use this helper to simplify the code.

> -	for_each_child_of_node(dev->ofdev.dev.of_node, np) {
> +	for_each_child_of_node_scoped(dev->ofdev.dev.of_node, np) {
>  		if (of_device_is_compatible(np, "i2sbus") ||
>  		    of_device_is_compatible(np, "i2s-modem")) {
>  			got += i2sbus_add_dev(dev, control, np);

Given the structure of this code, this either fixes a leak, or is wrong.
I really don't know which of those two it is, it's been decades, but
either way it's not a change that simply "simplif[ies] the code".

johannes
Christophe Leroy May 23, 2025, 10:51 a.m. UTC | #2
Le 22/05/2025 à 07:02, Ai Chao a écrit :
> The for_each_child_of_node_scoped() helper provides a scope-based
> clean-up functionality to put the device_node automatically, and
> as such, there is no need to call of_node_put() directly.

I don't understand this explanation.

You say "no need to call of_node_put()" and the only thing you do in 
addition to changing from for_each_child_of_node() to 
for_each_child_of_node_scoped() is to _add_ a new call to of_node_put().

I would expect to see a _removal_ of some of_node_put() when I read your 
description.

Christophe

> 
> Thus, use this helper to simplify the code.
> 
> Signed-off-by: Ai Chao <aichao@kylinos.cn>
> ---
>   sound/aoa/soundbus/i2sbus/core.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/aoa/soundbus/i2sbus/core.c b/sound/aoa/soundbus/i2sbus/core.c
> index ce84288168e4..20a4c5891afc 100644
> --- a/sound/aoa/soundbus/i2sbus/core.c
> +++ b/sound/aoa/soundbus/i2sbus/core.c
> @@ -207,6 +207,8 @@ static int i2sbus_add_dev(struct macio_dev *macio,
>   			}
>   		}
>   	}
> +	of_node_put(sound);
> +
>   	/* for the time being, until we can handle non-layout-id
>   	 * things in some fabric, refuse to attach if there is no
>   	 * layout-id property or we haven't been forced to attach.
> @@ -335,7 +337,6 @@ static int i2sbus_add_dev(struct macio_dev *macio,
>   
>   static int i2sbus_probe(struct macio_dev* dev, const struct of_device_id *match)
>   {
> -	struct device_node *np;
>   	int got = 0, err;
>   	struct i2sbus_control *control = NULL;
>   
> @@ -347,7 +348,7 @@ static int i2sbus_probe(struct macio_dev* dev, const struct of_device_id *match)
>   		return -ENODEV;
>   	}
>   
> -	for_each_child_of_node(dev->ofdev.dev.of_node, np) {
> +	for_each_child_of_node_scoped(dev->ofdev.dev.of_node, np) {
>   		if (of_device_is_compatible(np, "i2sbus") ||
>   		    of_device_is_compatible(np, "i2s-modem")) {
>   			got += i2sbus_add_dev(dev, control, np);
diff mbox series

Patch

diff --git a/sound/aoa/soundbus/i2sbus/core.c b/sound/aoa/soundbus/i2sbus/core.c
index ce84288168e4..20a4c5891afc 100644
--- a/sound/aoa/soundbus/i2sbus/core.c
+++ b/sound/aoa/soundbus/i2sbus/core.c
@@ -207,6 +207,8 @@  static int i2sbus_add_dev(struct macio_dev *macio,
 			}
 		}
 	}
+	of_node_put(sound);
+
 	/* for the time being, until we can handle non-layout-id
 	 * things in some fabric, refuse to attach if there is no
 	 * layout-id property or we haven't been forced to attach.
@@ -335,7 +337,6 @@  static int i2sbus_add_dev(struct macio_dev *macio,
 
 static int i2sbus_probe(struct macio_dev* dev, const struct of_device_id *match)
 {
-	struct device_node *np;
 	int got = 0, err;
 	struct i2sbus_control *control = NULL;
 
@@ -347,7 +348,7 @@  static int i2sbus_probe(struct macio_dev* dev, const struct of_device_id *match)
 		return -ENODEV;
 	}
 
-	for_each_child_of_node(dev->ofdev.dev.of_node, np) {
+	for_each_child_of_node_scoped(dev->ofdev.dev.of_node, np) {
 		if (of_device_is_compatible(np, "i2sbus") ||
 		    of_device_is_compatible(np, "i2s-modem")) {
 			got += i2sbus_add_dev(dev, control, np);