* [PATCH v2 0/6] Use helper function for_each_child_of_node_scoped()
@ 2025-05-22 5:02 Ai Chao
2025-05-22 5:02 ` [PATCH v2 1/6] ASoC: ppc: " Ai Chao
` (5 more replies)
0 siblings, 6 replies; 19+ messages in thread
From: Ai Chao @ 2025-05-22 5:02 UTC (permalink / raw)
To: perex, tiwai, johannes, kuninori.morimoto.gx, lgirdwood, broonie,
jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm,
Ai Chao
This patch series introduces wrapper functions for_each_child_of_node_scoped().
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.
Summary:
- Patch 1 ASoC: ppc: Use helper function for_each_child_of_node_scoped()
- Patch 2 ASoC: aoa: Use helper function for_each_child_of_node_scoped()
- Patch 3 ASoC: renesas: Use helper function for_each_child_of_node_scoped()
- Patch 4 ASoC: meson: Use helper function for_each_child_of_node_scoped()
- Patch 5 ASoC: imx-card: Use helper function for_each_child_of_node_scoped()
- Patch 6 ASoC: qcom: Use helper function for_each_child_of_node_scoped()
---
Changes in v2:
- Fix error reported by kernel test rebot
- Keep "node"
---
sound/aoa/soundbus/i2sbus/core.c | 5 +++--
sound/ppc/tumbler.c | 5 ++---
sound/soc/fsl/imx-card.c | 13 +++++------
sound/soc/meson/axg-card.c | 3 +--
sound/soc/meson/meson-card-utils.c | 16 +++++---------
sound/soc/qcom/lpass-cpu.c | 3 +--
sound/soc/qcom/qdsp6/q6afe-dai.c | 3 +--
sound/soc/qcom/qdsp6/q6asm-dai.c | 4 +---
sound/soc/renesas/rcar/core.c | 35 ++++++++++--------------------
sound/soc/renesas/rcar/ctu.c | 8 ++-----
sound/soc/renesas/rcar/dma.c | 4 +---
sound/soc/renesas/rcar/dvc.c | 8 ++-----
sound/soc/renesas/rcar/mix.c | 8 ++-----
sound/soc/renesas/rcar/src.c | 10 ++-------
sound/soc/renesas/rcar/ssi.c | 18 +++++----------
sound/soc/renesas/rcar/ssiu.c | 7 ++----
16 files changed, 46 insertions(+), 104 deletions(-)
--
2.47.1
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v2 1/6] ASoC: ppc: Use helper function for_each_child_of_node_scoped()
2025-05-22 5:02 [PATCH v2 0/6] Use helper function for_each_child_of_node_scoped() Ai Chao
@ 2025-05-22 5:02 ` Ai Chao
2025-05-22 10:00 ` Mark Brown
2025-05-22 5:02 ` [PATCH v2 2/6] ASoC: aoa: " Ai Chao
` (4 subsequent siblings)
5 siblings, 1 reply; 19+ messages in thread
From: Ai Chao @ 2025-05-22 5:02 UTC (permalink / raw)
To: perex, tiwai, johannes, kuninori.morimoto.gx, lgirdwood, broonie,
jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm,
Ai Chao
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/ppc/tumbler.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/sound/ppc/tumbler.c b/sound/ppc/tumbler.c
index 3c09660e1522..b81d0789b9fb 100644
--- a/sound/ppc/tumbler.c
+++ b/sound/ppc/tumbler.c
@@ -1343,7 +1343,7 @@ int snd_pmac_tumbler_init(struct snd_pmac *chip)
int i, err;
struct pmac_tumbler *mix;
const u32 *paddr;
- struct device_node *tas_node, *np;
+ struct device_node *tas_node;
char *chipname;
request_module("i2c-powermac");
@@ -1358,13 +1358,12 @@ int snd_pmac_tumbler_init(struct snd_pmac *chip)
mix->anded_reset = 0;
mix->reset_on_sleep = 1;
- for_each_child_of_node(chip->node, np) {
+ for_each_child_of_node_scoped(chip->node, np) {
if (of_node_name_eq(np, "sound")) {
if (of_property_read_bool(np, "has-anded-reset"))
mix->anded_reset = 1;
if (of_property_present(np, "layout-id"))
mix->reset_on_sleep = 0;
- of_node_put(np);
break;
}
}
--
2.47.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v2 2/6] ASoC: aoa: Use helper function for_each_child_of_node_scoped()
2025-05-22 5:02 [PATCH v2 0/6] Use helper function for_each_child_of_node_scoped() Ai Chao
2025-05-22 5:02 ` [PATCH v2 1/6] ASoC: ppc: " Ai Chao
@ 2025-05-22 5:02 ` Ai Chao
2025-05-22 10:04 ` Johannes Berg
2025-05-23 10:51 ` Christophe Leroy
2025-05-22 5:02 ` [PATCH v2 3/6] ASoC: renesas: " Ai Chao
` (3 subsequent siblings)
5 siblings, 2 replies; 19+ messages in thread
From: Ai Chao @ 2025-05-22 5:02 UTC (permalink / raw)
To: perex, tiwai, johannes, kuninori.morimoto.gx, lgirdwood, broonie,
jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm,
Ai Chao
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(-)
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);
--
2.47.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v2 3/6] ASoC: renesas: Use helper function for_each_child_of_node_scoped()
2025-05-22 5:02 [PATCH v2 0/6] Use helper function for_each_child_of_node_scoped() Ai Chao
2025-05-22 5:02 ` [PATCH v2 1/6] ASoC: ppc: " Ai Chao
2025-05-22 5:02 ` [PATCH v2 2/6] ASoC: aoa: " Ai Chao
@ 2025-05-22 5:02 ` Ai Chao
2025-05-22 5:02 ` [PATCH v2 4/6] ASoC: meson: " Ai Chao
` (2 subsequent siblings)
5 siblings, 0 replies; 19+ messages in thread
From: Ai Chao @ 2025-05-22 5:02 UTC (permalink / raw)
To: perex, tiwai, johannes, kuninori.morimoto.gx, lgirdwood, broonie,
jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm,
Ai Chao
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.
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Ai Chao <aichao@kylinos.cn>
---
sound/soc/renesas/rcar/core.c | 35 +++++++++++------------------------
sound/soc/renesas/rcar/ctu.c | 8 ++------
sound/soc/renesas/rcar/dma.c | 4 +---
sound/soc/renesas/rcar/dvc.c | 8 ++------
sound/soc/renesas/rcar/mix.c | 8 ++------
sound/soc/renesas/rcar/src.c | 10 ++--------
sound/soc/renesas/rcar/ssi.c | 18 +++++-------------
sound/soc/renesas/rcar/ssiu.c | 7 ++-----
8 files changed, 27 insertions(+), 71 deletions(-)
diff --git a/sound/soc/renesas/rcar/core.c b/sound/soc/renesas/rcar/core.c
index 30afc942d381..260c71888061 100644
--- a/sound/soc/renesas/rcar/core.c
+++ b/sound/soc/renesas/rcar/core.c
@@ -1075,7 +1075,6 @@ static void rsnd_parse_tdm_split_mode(struct rsnd_priv *priv,
{
struct device *dev = rsnd_priv_to_dev(priv);
struct device_node *ssiu_np = rsnd_ssiu_of_node(priv);
- struct device_node *np;
int is_play = rsnd_io_is_play(io);
int i;
@@ -1094,7 +1093,7 @@ static void rsnd_parse_tdm_split_mode(struct rsnd_priv *priv,
if (!node)
break;
- for_each_child_of_node(ssiu_np, np) {
+ for_each_child_of_node_scoped(ssiu_np, np) {
if (np == node) {
rsnd_flags_set(io, RSND_STREAM_TDM_SPLIT);
dev_dbg(dev, "%s is part of TDM Split\n", io->name);
@@ -1154,21 +1153,18 @@ void rsnd_parse_connect_common(struct rsnd_dai *rdai, char *name,
{
struct rsnd_priv *priv = rsnd_rdai_to_priv(rdai);
struct device *dev = rsnd_priv_to_dev(priv);
- struct device_node *np;
int i;
if (!node)
return;
i = 0;
- for_each_child_of_node(node, np) {
+ for_each_child_of_node_scoped(node, np) {
struct rsnd_mod *mod;
i = rsnd_node_fixed_index(dev, np, name, i);
- if (i < 0) {
- of_node_put(np);
+ if (i < 0)
break;
- }
mod = mod_get(priv, i);
@@ -1217,16 +1213,13 @@ int rsnd_node_fixed_index(struct device *dev, struct device_node *node, char *na
int rsnd_node_count(struct rsnd_priv *priv, struct device_node *node, char *name)
{
struct device *dev = rsnd_priv_to_dev(priv);
- struct device_node *np;
int i;
i = 0;
- for_each_child_of_node(node, np) {
+ for_each_child_of_node_scoped(node, np) {
i = rsnd_node_fixed_index(dev, np, name, i);
- if (i < 0) {
- of_node_put(np);
+ if (i < 0)
return 0;
- }
i++;
}
@@ -1250,7 +1243,7 @@ static int rsnd_dai_of_node(struct rsnd_priv *priv, int *is_graph)
{
struct device *dev = rsnd_priv_to_dev(priv);
struct device_node *np = dev->of_node;
- struct device_node *ports, *node;
+ struct device_node *node;
int nr = 0;
int i = 0;
@@ -1270,7 +1263,7 @@ static int rsnd_dai_of_node(struct rsnd_priv *priv, int *is_graph)
of_node_put(node);
- for_each_child_of_node(np, node) {
+ for_each_child_of_node_scoped(np, node) {
if (!of_node_name_eq(node, RSND_NODE_DAI))
continue;
@@ -1279,7 +1272,6 @@ static int rsnd_dai_of_node(struct rsnd_priv *priv, int *is_graph)
i++;
if (i >= RSND_MAX_COMPONENT) {
dev_info(dev, "reach to max component\n");
- of_node_put(node);
break;
}
}
@@ -1290,7 +1282,7 @@ static int rsnd_dai_of_node(struct rsnd_priv *priv, int *is_graph)
/*
* Audio-Graph-Card
*/
- for_each_child_of_node(np, ports) {
+ for_each_child_of_node_scoped(np, ports) {
node = rsnd_pick_endpoint_node_for_ports(ports, np);
if (!node)
continue;
@@ -1299,7 +1291,6 @@ static int rsnd_dai_of_node(struct rsnd_priv *priv, int *is_graph)
i++;
if (i >= RSND_MAX_COMPONENT) {
dev_info(dev, "reach to max component\n");
- of_node_put(ports);
break;
}
}
@@ -1500,10 +1491,9 @@ static int rsnd_dai_probe(struct rsnd_priv *priv)
dai_i = 0;
if (is_graph) {
struct device_node *dai_np_port;
- struct device_node *ports;
struct device_node *dai_np;
- for_each_child_of_node(np, ports) {
+ for_each_child_of_node_scoped(np, ports) {
dai_np_port = rsnd_pick_endpoint_node_for_ports(ports, np);
if (!dai_np_port)
continue;
@@ -1520,14 +1510,11 @@ static int rsnd_dai_probe(struct rsnd_priv *priv)
}
}
} else {
- struct device_node *node;
- struct device_node *dai_np;
-
- for_each_child_of_node(np, node) {
+ for_each_child_of_node_scoped(np, node) {
if (!of_node_name_eq(node, RSND_NODE_DAI))
continue;
- for_each_child_of_node(node, dai_np) {
+ for_each_child_of_node_scoped(node, dai_np) {
__rsnd_dai_probe(priv, dai_np, np, dai_i, dai_i);
if (!rsnd_is_gen1(priv) && !rsnd_is_gen2(priv)) {
rdai = rsnd_rdai_get(priv, dai_i);
diff --git a/sound/soc/renesas/rcar/ctu.c b/sound/soc/renesas/rcar/ctu.c
index a26ec7b780cd..bd4c61f9fb3c 100644
--- a/sound/soc/renesas/rcar/ctu.c
+++ b/sound/soc/renesas/rcar/ctu.c
@@ -316,7 +316,6 @@ struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id)
int rsnd_ctu_probe(struct rsnd_priv *priv)
{
struct device_node *node;
- struct device_node *np;
struct device *dev = rsnd_priv_to_dev(priv);
struct rsnd_ctu *ctu;
struct clk *clk;
@@ -344,7 +343,7 @@ int rsnd_ctu_probe(struct rsnd_priv *priv)
i = 0;
ret = 0;
- for_each_child_of_node(node, np) {
+ for_each_child_of_node_scoped(node, np) {
ctu = rsnd_ctu_get(priv, i);
/*
@@ -357,16 +356,13 @@ int rsnd_ctu_probe(struct rsnd_priv *priv)
clk = devm_clk_get(dev, name);
if (IS_ERR(clk)) {
ret = PTR_ERR(clk);
- of_node_put(np);
goto rsnd_ctu_probe_done;
}
ret = rsnd_mod_init(priv, rsnd_mod_get(ctu), &rsnd_ctu_ops,
clk, RSND_MOD_CTU, i);
- if (ret) {
- of_node_put(np);
+ if (ret)
goto rsnd_ctu_probe_done;
- }
i++;
}
diff --git a/sound/soc/renesas/rcar/dma.c b/sound/soc/renesas/rcar/dma.c
index 2342bbb6fe92..2035ce06fe4c 100644
--- a/sound/soc/renesas/rcar/dma.c
+++ b/sound/soc/renesas/rcar/dma.c
@@ -194,14 +194,12 @@ struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, char *nam
struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
struct device *dev = rsnd_priv_to_dev(priv);
struct dma_chan *chan = NULL;
- struct device_node *np;
int i = 0;
- for_each_child_of_node(of_node, np) {
+ for_each_child_of_node_scoped(of_node, np) {
i = rsnd_node_fixed_index(dev, np, name, i);
if (i < 0) {
chan = NULL;
- of_node_put(np);
break;
}
diff --git a/sound/soc/renesas/rcar/dvc.c b/sound/soc/renesas/rcar/dvc.c
index da91dd301aab..988cbddbc611 100644
--- a/sound/soc/renesas/rcar/dvc.c
+++ b/sound/soc/renesas/rcar/dvc.c
@@ -324,7 +324,6 @@ struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id)
int rsnd_dvc_probe(struct rsnd_priv *priv)
{
struct device_node *node;
- struct device_node *np;
struct device *dev = rsnd_priv_to_dev(priv);
struct rsnd_dvc *dvc;
struct clk *clk;
@@ -352,7 +351,7 @@ int rsnd_dvc_probe(struct rsnd_priv *priv)
i = 0;
ret = 0;
- for_each_child_of_node(node, np) {
+ for_each_child_of_node_scoped(node, np) {
dvc = rsnd_dvc_get(priv, i);
snprintf(name, RSND_DVC_NAME_SIZE, "%s.%d",
@@ -361,16 +360,13 @@ int rsnd_dvc_probe(struct rsnd_priv *priv)
clk = devm_clk_get(dev, name);
if (IS_ERR(clk)) {
ret = PTR_ERR(clk);
- of_node_put(np);
goto rsnd_dvc_probe_done;
}
ret = rsnd_mod_init(priv, rsnd_mod_get(dvc), &rsnd_dvc_ops,
clk, RSND_MOD_DVC, i);
- if (ret) {
- of_node_put(np);
+ if (ret)
goto rsnd_dvc_probe_done;
- }
i++;
}
diff --git a/sound/soc/renesas/rcar/mix.c b/sound/soc/renesas/rcar/mix.c
index 024d91cc8748..aea74e703305 100644
--- a/sound/soc/renesas/rcar/mix.c
+++ b/sound/soc/renesas/rcar/mix.c
@@ -288,7 +288,6 @@ struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id)
int rsnd_mix_probe(struct rsnd_priv *priv)
{
struct device_node *node;
- struct device_node *np;
struct device *dev = rsnd_priv_to_dev(priv);
struct rsnd_mix *mix;
struct clk *clk;
@@ -316,7 +315,7 @@ int rsnd_mix_probe(struct rsnd_priv *priv)
i = 0;
ret = 0;
- for_each_child_of_node(node, np) {
+ for_each_child_of_node_scoped(node, np) {
mix = rsnd_mix_get(priv, i);
snprintf(name, MIX_NAME_SIZE, "%s.%d",
@@ -325,16 +324,13 @@ int rsnd_mix_probe(struct rsnd_priv *priv)
clk = devm_clk_get(dev, name);
if (IS_ERR(clk)) {
ret = PTR_ERR(clk);
- of_node_put(np);
goto rsnd_mix_probe_done;
}
ret = rsnd_mod_init(priv, rsnd_mod_get(mix), &rsnd_mix_ops,
clk, RSND_MOD_MIX, i);
- if (ret) {
- of_node_put(np);
+ if (ret)
goto rsnd_mix_probe_done;
- }
i++;
}
diff --git a/sound/soc/renesas/rcar/src.c b/sound/soc/renesas/rcar/src.c
index 7d73b183bda6..f47bf38c2f94 100644
--- a/sound/soc/renesas/rcar/src.c
+++ b/sound/soc/renesas/rcar/src.c
@@ -715,7 +715,6 @@ struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)
int rsnd_src_probe(struct rsnd_priv *priv)
{
struct device_node *node;
- struct device_node *np;
struct device *dev = rsnd_priv_to_dev(priv);
struct rsnd_src *src;
struct clk *clk;
@@ -742,14 +741,13 @@ int rsnd_src_probe(struct rsnd_priv *priv)
priv->src = src;
i = 0;
- for_each_child_of_node(node, np) {
+ for_each_child_of_node_scoped(node, np) {
if (!of_device_is_available(np))
goto skip;
i = rsnd_node_fixed_index(dev, np, SRC_NAME, i);
if (i < 0) {
ret = -EINVAL;
- of_node_put(np);
goto rsnd_src_probe_done;
}
@@ -761,23 +759,19 @@ int rsnd_src_probe(struct rsnd_priv *priv)
src->irq = irq_of_parse_and_map(np, 0);
if (!src->irq) {
ret = -EINVAL;
- of_node_put(np);
goto rsnd_src_probe_done;
}
clk = devm_clk_get(dev, name);
if (IS_ERR(clk)) {
ret = PTR_ERR(clk);
- of_node_put(np);
goto rsnd_src_probe_done;
}
ret = rsnd_mod_init(priv, rsnd_mod_get(src),
&rsnd_src_ops, clk, RSND_MOD_SRC, i);
- if (ret) {
- of_node_put(np);
+ if (ret)
goto rsnd_src_probe_done;
- }
skip:
i++;
diff --git a/sound/soc/renesas/rcar/ssi.c b/sound/soc/renesas/rcar/ssi.c
index 0c6424a1fcac..d52056caa3ec 100644
--- a/sound/soc/renesas/rcar/ssi.c
+++ b/sound/soc/renesas/rcar/ssi.c
@@ -1115,7 +1115,6 @@ void rsnd_parse_connect_ssi(struct rsnd_dai *rdai,
struct rsnd_priv *priv = rsnd_rdai_to_priv(rdai);
struct device *dev = rsnd_priv_to_dev(priv);
struct device_node *node;
- struct device_node *np;
int i;
node = rsnd_ssi_of_node(priv);
@@ -1123,14 +1122,12 @@ void rsnd_parse_connect_ssi(struct rsnd_dai *rdai,
return;
i = 0;
- for_each_child_of_node(node, np) {
+ for_each_child_of_node_scoped(node, np) {
struct rsnd_mod *mod;
i = rsnd_node_fixed_index(dev, np, SSI_NAME, i);
- if (i < 0) {
- of_node_put(np);
+ if (i < 0)
break;
- }
mod = rsnd_ssi_mod_get(priv, i);
@@ -1163,7 +1160,6 @@ int __rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
int rsnd_ssi_probe(struct rsnd_priv *priv)
{
struct device_node *node;
- struct device_node *np;
struct device *dev = rsnd_priv_to_dev(priv);
struct rsnd_mod_ops *ops;
struct clk *clk;
@@ -1191,14 +1187,13 @@ int rsnd_ssi_probe(struct rsnd_priv *priv)
priv->ssi_nr = nr;
i = 0;
- for_each_child_of_node(node, np) {
+ for_each_child_of_node_scoped(node, np) {
if (!of_device_is_available(np))
goto skip;
i = rsnd_node_fixed_index(dev, np, SSI_NAME, i);
if (i < 0) {
ret = -EINVAL;
- of_node_put(np);
goto rsnd_ssi_probe_done;
}
@@ -1210,7 +1205,6 @@ int rsnd_ssi_probe(struct rsnd_priv *priv)
clk = devm_clk_get(dev, name);
if (IS_ERR(clk)) {
ret = PTR_ERR(clk);
- of_node_put(np);
goto rsnd_ssi_probe_done;
}
@@ -1223,7 +1217,6 @@ int rsnd_ssi_probe(struct rsnd_priv *priv)
ssi->irq = irq_of_parse_and_map(np, 0);
if (!ssi->irq) {
ret = -EINVAL;
- of_node_put(np);
goto rsnd_ssi_probe_done;
}
@@ -1234,10 +1227,9 @@ int rsnd_ssi_probe(struct rsnd_priv *priv)
ret = rsnd_mod_init(priv, rsnd_mod_get(ssi), ops, clk,
RSND_MOD_SSI, i);
- if (ret) {
- of_node_put(np);
+ if (ret)
goto rsnd_ssi_probe_done;
- }
+
skip:
i++;
}
diff --git a/sound/soc/renesas/rcar/ssiu.c b/sound/soc/renesas/rcar/ssiu.c
index 665e8b2db579..faf351126d57 100644
--- a/sound/soc/renesas/rcar/ssiu.c
+++ b/sound/soc/renesas/rcar/ssiu.c
@@ -478,17 +478,14 @@ void rsnd_parse_connect_ssiu(struct rsnd_dai *rdai,
/* use rcar_sound,ssiu if exist */
if (node) {
- struct device_node *np;
int i = 0;
- for_each_child_of_node(node, np) {
+ for_each_child_of_node_scoped(node, np) {
struct rsnd_mod *mod;
i = rsnd_node_fixed_index(dev, np, SSIU_NAME, i);
- if (i < 0) {
- of_node_put(np);
+ if (i < 0)
break;
- }
mod = rsnd_ssiu_mod_get(priv, i);
--
2.47.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v2 4/6] ASoC: meson: Use helper function for_each_child_of_node_scoped()
2025-05-22 5:02 [PATCH v2 0/6] Use helper function for_each_child_of_node_scoped() Ai Chao
` (2 preceding siblings ...)
2025-05-22 5:02 ` [PATCH v2 3/6] ASoC: renesas: " Ai Chao
@ 2025-05-22 5:02 ` Ai Chao
2025-05-22 5:02 ` [PATCH v2 5/6] ASoC: imx-card: " Ai Chao
2025-05-22 5:02 ` [PATCH v2 6/6] ASoC: qcom: " Ai Chao
5 siblings, 0 replies; 19+ messages in thread
From: Ai Chao @ 2025-05-22 5:02 UTC (permalink / raw)
To: perex, tiwai, johannes, kuninori.morimoto.gx, lgirdwood, broonie,
jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm,
Ai Chao, kernel test robot
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.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202505210557.EpJig9BQ-lkp@intel.com/
Signed-off-by: Ai Chao <aichao@kylinos.cn>
---
sound/soc/meson/axg-card.c | 3 +--
sound/soc/meson/meson-card-utils.c | 16 +++++-----------
2 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/sound/soc/meson/axg-card.c b/sound/soc/meson/axg-card.c
index a2dfccb7990f..b4dca80e15e4 100644
--- a/sound/soc/meson/axg-card.c
+++ b/sound/soc/meson/axg-card.c
@@ -222,7 +222,6 @@ static int axg_card_parse_codecs_masks(struct snd_soc_card *card,
struct axg_dai_link_tdm_data *be)
{
struct axg_dai_link_tdm_mask *codec_mask;
- struct device_node *np;
codec_mask = devm_kcalloc(card->dev, link->num_codecs,
sizeof(*codec_mask), GFP_KERNEL);
@@ -231,7 +230,7 @@ static int axg_card_parse_codecs_masks(struct snd_soc_card *card,
be->codec_masks = codec_mask;
- for_each_child_of_node(node, np) {
+ for_each_child_of_node_scoped(node, np) {
snd_soc_of_get_slot_mask(np, "dai-tdm-slot-rx-mask",
&codec_mask->rx);
snd_soc_of_get_slot_mask(np, "dai-tdm-slot-tx-mask",
diff --git a/sound/soc/meson/meson-card-utils.c b/sound/soc/meson/meson-card-utils.c
index cfc7f6e41ab5..0750dece9e69 100644
--- a/sound/soc/meson/meson-card-utils.c
+++ b/sound/soc/meson/meson-card-utils.c
@@ -137,7 +137,6 @@ int meson_card_set_be_link(struct snd_soc_card *card,
struct device_node *node)
{
struct snd_soc_dai_link_component *codec;
- struct device_node *np;
int ret, num_codecs;
num_codecs = of_get_child_count(node);
@@ -154,19 +153,17 @@ int meson_card_set_be_link(struct snd_soc_card *card,
link->codecs = codec;
link->num_codecs = num_codecs;
- for_each_child_of_node(node, np) {
+ for_each_child_of_node_scoped(node, np) {
ret = meson_card_parse_dai(card, np, codec);
- if (ret) {
- of_node_put(np);
+ if (ret)
return ret;
- }
codec++;
}
ret = meson_card_set_link_name(card, link, node, "be");
if (ret)
- dev_err(card->dev, "error setting %pOFn link name\n", np);
+ dev_err(card->dev, "error setting %pOFn link name\n", node);
return ret;
}
@@ -198,7 +195,6 @@ static int meson_card_add_links(struct snd_soc_card *card)
{
struct meson_card *priv = snd_soc_card_get_drvdata(card);
struct device_node *node = card->dev->of_node;
- struct device_node *np;
int num, i, ret;
num = of_get_child_count(node);
@@ -212,12 +208,10 @@ static int meson_card_add_links(struct snd_soc_card *card)
return ret;
i = 0;
- for_each_child_of_node(node, np) {
+ for_each_child_of_node_scoped(node, np) {
ret = priv->match_data->add_link(card, np, &i);
- if (ret) {
- of_node_put(np);
+ if (ret)
return ret;
- }
i++;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v2 5/6] ASoC: imx-card: Use helper function for_each_child_of_node_scoped()
2025-05-22 5:02 [PATCH v2 0/6] Use helper function for_each_child_of_node_scoped() Ai Chao
` (3 preceding siblings ...)
2025-05-22 5:02 ` [PATCH v2 4/6] ASoC: meson: " Ai Chao
@ 2025-05-22 5:02 ` Ai Chao
2025-05-22 5:02 ` [PATCH v2 6/6] ASoC: qcom: " Ai Chao
5 siblings, 0 replies; 19+ messages in thread
From: Ai Chao @ 2025-05-22 5:02 UTC (permalink / raw)
To: perex, tiwai, johannes, kuninori.morimoto.gx, lgirdwood, broonie,
jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm,
Ai Chao
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/soc/fsl/imx-card.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/sound/soc/fsl/imx-card.c b/sound/soc/fsl/imx-card.c
index 3686d468506b..bffdba4292b6 100644
--- a/sound/soc/fsl/imx-card.c
+++ b/sound/soc/fsl/imx-card.c
@@ -513,7 +513,6 @@ static int imx_card_parse_of(struct imx_card_data *data)
struct device_node *platform = NULL;
struct device_node *codec = NULL;
struct device_node *cpu = NULL;
- struct device_node *np;
struct device *dev = card->dev;
struct snd_soc_dai_link *link;
struct dai_link_data *link_data;
@@ -552,11 +551,10 @@ static int imx_card_parse_of(struct imx_card_data *data)
link = card->dai_link;
link_data = data->link_data;
- for_each_child_of_node(dev->of_node, np) {
+ for_each_child_of_node_scoped(dev->of_node, np) {
dlc = devm_kzalloc(dev, 2 * sizeof(*dlc), GFP_KERNEL);
if (!dlc) {
- ret = -ENOMEM;
- goto err_put_np;
+ return -ENOMEM;
}
link->cpus = &dlc[0];
@@ -567,8 +565,8 @@ static int imx_card_parse_of(struct imx_card_data *data)
ret = of_property_read_string(np, "link-name", &link->name);
if (ret) {
- dev_err(card->dev, "error getting codec dai_link name\n");
- goto err_put_np;
+ return dev_err_probe(card->dev, ret,
+ "error getting codec dai_link name\n");
}
cpu = of_get_child_by_name(np, "cpu");
@@ -722,8 +720,7 @@ static int imx_card_parse_of(struct imx_card_data *data)
of_node_put(cpu);
of_node_put(codec);
of_node_put(platform);
-err_put_np:
- of_node_put(np);
+
return ret;
}
--
2.47.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v2 6/6] ASoC: qcom: Use helper function for_each_child_of_node_scoped()
2025-05-22 5:02 [PATCH v2 0/6] Use helper function for_each_child_of_node_scoped() Ai Chao
` (4 preceding siblings ...)
2025-05-22 5:02 ` [PATCH v2 5/6] ASoC: imx-card: " Ai Chao
@ 2025-05-22 5:02 ` Ai Chao
2025-05-22 12:37 ` Dmitry Baryshkov
5 siblings, 1 reply; 19+ messages in thread
From: Ai Chao @ 2025-05-22 5:02 UTC (permalink / raw)
To: perex, tiwai, johannes, kuninori.morimoto.gx, lgirdwood, broonie,
jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm,
Ai Chao
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/soc/qcom/lpass-cpu.c | 3 +--
sound/soc/qcom/qdsp6/q6afe-dai.c | 3 +--
sound/soc/qcom/qdsp6/q6asm-dai.c | 4 +---
3 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/sound/soc/qcom/lpass-cpu.c b/sound/soc/qcom/lpass-cpu.c
index 242bc16da36d..62f49fe46273 100644
--- a/sound/soc/qcom/lpass-cpu.c
+++ b/sound/soc/qcom/lpass-cpu.c
@@ -1046,7 +1046,6 @@ static unsigned int of_lpass_cpu_parse_sd_lines(struct device *dev,
static void of_lpass_cpu_parse_dai_data(struct device *dev,
struct lpass_data *data)
{
- struct device_node *node;
int ret, i, id;
/* Allow all channels by default for backwards compatibility */
@@ -1056,7 +1055,7 @@ static void of_lpass_cpu_parse_dai_data(struct device *dev,
data->mi2s_capture_sd_mode[id] = LPAIF_I2SCTL_MODE_8CH;
}
- for_each_child_of_node(dev->of_node, node) {
+ for_each_child_of_node_scoped(dev->of_node, node) {
ret = of_property_read_u32(node, "reg", &id);
if (ret || id < 0) {
dev_err(dev, "valid dai id not found: %d\n", ret);
diff --git a/sound/soc/qcom/qdsp6/q6afe-dai.c b/sound/soc/qcom/qdsp6/q6afe-dai.c
index 7d9628cda875..64735f2adf8f 100644
--- a/sound/soc/qcom/qdsp6/q6afe-dai.c
+++ b/sound/soc/qcom/qdsp6/q6afe-dai.c
@@ -962,10 +962,9 @@ static const struct snd_soc_component_driver q6afe_dai_component = {
static void of_q6afe_parse_dai_data(struct device *dev,
struct q6afe_dai_data *data)
{
- struct device_node *node;
int ret;
- for_each_child_of_node(dev->of_node, node) {
+ for_each_child_of_node_scoped(dev->of_node, node) {
unsigned int lines[Q6AFE_MAX_MI2S_LINES];
struct q6afe_dai_priv_data *priv;
int id, i, num_lines;
diff --git a/sound/soc/qcom/qdsp6/q6asm-dai.c b/sound/soc/qcom/qdsp6/q6asm-dai.c
index a400c9a31fea..d7680dd3a3bb 100644
--- a/sound/soc/qcom/qdsp6/q6asm-dai.c
+++ b/sound/soc/qcom/qdsp6/q6asm-dai.c
@@ -1236,10 +1236,8 @@ static int of_q6asm_parse_dai_data(struct device *dev,
{
struct snd_soc_dai_driver *dai_drv;
struct snd_soc_pcm_stream empty_stream;
- struct device_node *node;
int ret, id, dir, idx = 0;
-
pdata->num_dais = of_get_child_count(dev->of_node);
if (!pdata->num_dais) {
dev_err(dev, "No dais found in DT\n");
@@ -1253,7 +1251,7 @@ static int of_q6asm_parse_dai_data(struct device *dev,
memset(&empty_stream, 0, sizeof(empty_stream));
- for_each_child_of_node(dev->of_node, node) {
+ for_each_child_of_node_scoped(dev->of_node, node) {
ret = of_property_read_u32(node, "reg", &id);
if (ret || id >= MAX_SESSIONS || id < 0) {
dev_err(dev, "valid dai id not found:%d\n", ret);
--
2.47.1
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH v2 1/6] ASoC: ppc: Use helper function for_each_child_of_node_scoped()
2025-05-22 5:02 ` [PATCH v2 1/6] ASoC: ppc: " Ai Chao
@ 2025-05-22 10:00 ` Mark Brown
0 siblings, 0 replies; 19+ messages in thread
From: Mark Brown @ 2025-05-22 10:00 UTC (permalink / raw)
To: Ai Chao
Cc: perex, tiwai, johannes, kuninori.morimoto.gx, lgirdwood, jbrunet,
neil.armstrong, khilman, martin.blumenstingl, shengjiu.wang,
Xiubo.Lee, festevam, nicoleotsuka, shawnguo, s.hauer,
srinivas.kandagatla, linux-sound, linux-kernel, linuxppc-dev,
linux-renesas-soc, linux-arm-kernel, linux-amlogic, imx, kernel,
linux-arm-msm
[-- Attachment #1: Type: text/plain, Size: 500 bytes --]
On Thu, May 22, 2025 at 01:02:54PM +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.
>
> Signed-off-by: Ai Chao <aichao@kylinos.cn>
> ---
> sound/ppc/tumbler.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
This is for ALSA, not ASoC (same for patch 2).
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 2/6] ASoC: aoa: Use helper function for_each_child_of_node_scoped()
2025-05-22 5:02 ` [PATCH v2 2/6] ASoC: aoa: " Ai Chao
@ 2025-05-22 10:04 ` Johannes Berg
2025-05-23 10:51 ` Christophe Leroy
1 sibling, 0 replies; 19+ messages in thread
From: Johannes Berg @ 2025-05-22 10:04 UTC (permalink / raw)
To: Ai Chao, perex, tiwai, kuninori.morimoto.gx, lgirdwood, broonie,
jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm
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
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 6/6] ASoC: qcom: Use helper function for_each_child_of_node_scoped()
2025-05-22 5:02 ` [PATCH v2 6/6] ASoC: qcom: " Ai Chao
@ 2025-05-22 12:37 ` Dmitry Baryshkov
0 siblings, 0 replies; 19+ messages in thread
From: Dmitry Baryshkov @ 2025-05-22 12:37 UTC (permalink / raw)
To: Ai Chao
Cc: perex, tiwai, johannes, kuninori.morimoto.gx, lgirdwood, broonie,
jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla, linux-sound, linux-kernel,
linuxppc-dev, linux-renesas-soc, linux-arm-kernel, linux-amlogic,
imx, kernel, linux-arm-msm
On Thu, May 22, 2025 at 01:02:59PM +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.
There are no calls to of_node_put() in the commit. So the commit message
is incorrect / not-applicable.
>
> Thus, use this helper to simplify the code.
>
> Signed-off-by: Ai Chao <aichao@kylinos.cn>
> ---
> sound/soc/qcom/lpass-cpu.c | 3 +--
> sound/soc/qcom/qdsp6/q6afe-dai.c | 3 +--
> sound/soc/qcom/qdsp6/q6asm-dai.c | 4 +---
> 3 files changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/sound/soc/qcom/lpass-cpu.c b/sound/soc/qcom/lpass-cpu.c
> index 242bc16da36d..62f49fe46273 100644
> --- a/sound/soc/qcom/lpass-cpu.c
> +++ b/sound/soc/qcom/lpass-cpu.c
> @@ -1046,7 +1046,6 @@ static unsigned int of_lpass_cpu_parse_sd_lines(struct device *dev,
> static void of_lpass_cpu_parse_dai_data(struct device *dev,
> struct lpass_data *data)
> {
> - struct device_node *node;
> int ret, i, id;
>
> /* Allow all channels by default for backwards compatibility */
> @@ -1056,7 +1055,7 @@ static void of_lpass_cpu_parse_dai_data(struct device *dev,
> data->mi2s_capture_sd_mode[id] = LPAIF_I2SCTL_MODE_8CH;
> }
>
> - for_each_child_of_node(dev->of_node, node) {
> + for_each_child_of_node_scoped(dev->of_node, node) {
> ret = of_property_read_u32(node, "reg", &id);
> if (ret || id < 0) {
> dev_err(dev, "valid dai id not found: %d\n", ret);
> diff --git a/sound/soc/qcom/qdsp6/q6afe-dai.c b/sound/soc/qcom/qdsp6/q6afe-dai.c
> index 7d9628cda875..64735f2adf8f 100644
> --- a/sound/soc/qcom/qdsp6/q6afe-dai.c
> +++ b/sound/soc/qcom/qdsp6/q6afe-dai.c
> @@ -962,10 +962,9 @@ static const struct snd_soc_component_driver q6afe_dai_component = {
> static void of_q6afe_parse_dai_data(struct device *dev,
> struct q6afe_dai_data *data)
> {
> - struct device_node *node;
> int ret;
>
> - for_each_child_of_node(dev->of_node, node) {
> + for_each_child_of_node_scoped(dev->of_node, node) {
> unsigned int lines[Q6AFE_MAX_MI2S_LINES];
> struct q6afe_dai_priv_data *priv;
> int id, i, num_lines;
> diff --git a/sound/soc/qcom/qdsp6/q6asm-dai.c b/sound/soc/qcom/qdsp6/q6asm-dai.c
> index a400c9a31fea..d7680dd3a3bb 100644
> --- a/sound/soc/qcom/qdsp6/q6asm-dai.c
> +++ b/sound/soc/qcom/qdsp6/q6asm-dai.c
> @@ -1236,10 +1236,8 @@ static int of_q6asm_parse_dai_data(struct device *dev,
> {
> struct snd_soc_dai_driver *dai_drv;
> struct snd_soc_pcm_stream empty_stream;
> - struct device_node *node;
> int ret, id, dir, idx = 0;
>
> -
> pdata->num_dais = of_get_child_count(dev->of_node);
> if (!pdata->num_dais) {
> dev_err(dev, "No dais found in DT\n");
> @@ -1253,7 +1251,7 @@ static int of_q6asm_parse_dai_data(struct device *dev,
>
> memset(&empty_stream, 0, sizeof(empty_stream));
>
> - for_each_child_of_node(dev->of_node, node) {
> + for_each_child_of_node_scoped(dev->of_node, node) {
> ret = of_property_read_u32(node, "reg", &id);
> if (ret || id >= MAX_SESSIONS || id < 0) {
> dev_err(dev, "valid dai id not found:%d\n", ret);
> --
> 2.47.1
>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 2/6] ASoC: aoa: Use helper function for_each_child_of_node_scoped()
[not found] <2aq0nyvyf7t-2aq4hsc7kp6@nsmail7.0.0--kylin--1>
@ 2025-05-23 10:40 ` Johannes Berg
2025-05-26 8:12 ` Ai Chao
0 siblings, 1 reply; 19+ messages in thread
From: Johannes Berg @ 2025-05-23 10:40 UTC (permalink / raw)
To: 艾超, perex, tiwai, kuninori.morimoto.gx, lgirdwood,
broonie, jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm
Hi,
[you should avoid HTML]
> "simplifies the code" is no need to callof_node_put() .
Fair. Except that's not what you _actually_ changed here. Like I said,
either it's buggy before or after.
johannes
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 2/6] ASoC: aoa: Use helper function for_each_child_of_node_scoped()
2025-05-22 5:02 ` [PATCH v2 2/6] ASoC: aoa: " Ai Chao
2025-05-22 10:04 ` Johannes Berg
@ 2025-05-23 10:51 ` Christophe Leroy
2025-05-26 8:53 ` Ai Chao
1 sibling, 1 reply; 19+ messages in thread
From: Christophe Leroy @ 2025-05-23 10:51 UTC (permalink / raw)
To: Ai Chao, perex, tiwai, johannes, kuninori.morimoto.gx, lgirdwood,
broonie, jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm
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);
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 2/6] ASoC: aoa: Use helper function for_each_child_of_node_scoped()
2025-05-23 10:40 ` [PATCH v2 2/6] ASoC: aoa: " Johannes Berg
@ 2025-05-26 8:12 ` Ai Chao
2025-05-26 8:13 ` Johannes Berg
0 siblings, 1 reply; 19+ messages in thread
From: Ai Chao @ 2025-05-26 8:12 UTC (permalink / raw)
To: Johannes Berg, perex, tiwai, kuninori.morimoto.gx, lgirdwood,
broonie, jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm
Hi Johannes:
>> "simplifies the code" is no need to callof_node_put() .
> Fair. Except that's not what you _actually_ changed here. Like I said,
> either it's buggy before or after.
>
In the function i2sbus_probe, it not return a struct device_node, so , I
think function for_each_child_of_node_scoped is better than
for_each_child_of_node.
Best regards,
Ai Chao
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 2/6] ASoC: aoa: Use helper function for_each_child_of_node_scoped()
2025-05-26 8:12 ` Ai Chao
@ 2025-05-26 8:13 ` Johannes Berg
2025-05-26 8:20 ` Ai Chao
0 siblings, 1 reply; 19+ messages in thread
From: Johannes Berg @ 2025-05-26 8:13 UTC (permalink / raw)
To: Ai Chao, perex, tiwai, kuninori.morimoto.gx, lgirdwood, broonie,
jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm
On Mon, 2025-05-26 at 16:12 +0800, Ai Chao wrote:
> Hi Johannes:
>
> > > "simplifies the code" is no need to callof_node_put() .
> > Fair. Except that's not what you _actually_ changed here. Like I said,
> > either it's buggy before or after.
> >
> In the function i2sbus_probe, it not return a struct device_node, so , I
> think function for_each_child_of_node_scoped is better than
> for_each_child_of_node.
You still haven't explained why it's even correct.
johannes
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 2/6] ASoC: aoa: Use helper function for_each_child_of_node_scoped()
2025-05-26 8:13 ` Johannes Berg
@ 2025-05-26 8:20 ` Ai Chao
2025-05-26 8:21 ` Johannes Berg
2025-05-28 19:23 ` Dmitry Baryshkov
0 siblings, 2 replies; 19+ messages in thread
From: Ai Chao @ 2025-05-26 8:20 UTC (permalink / raw)
To: Johannes Berg, perex, tiwai, kuninori.morimoto.gx, lgirdwood,
broonie, jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm
Hi Johannes:
>> Hi Johannes:
>>
>>>> "simplifies the code" is no need to callof_node_put() .
>>> Fair. Except that's not what you _actually_ changed here. Like I said,
>>> either it's buggy before or after.
>>>
>> In the function i2sbus_probe, it not return a struct device_node, so , I
>> think function for_each_child_of_node_scoped is better than
>> for_each_child_of_node.
> You still haven't explained why it's even correct.
>
> johannes
The for_each_child_of_node() function is used to iterate over all child
nodes of a device tree node.
During each iteration, it retrieves a pointer to the child node via
of_get_next_child() and automatically increments the node's reference
count (of_node_get()).
Each call to of_get_next_child() increases the reference count
(refcount) of the returned child node, ensuring that the node is not
freed while in use.
for_each_child_of_node() increments the child node's reference count in
each iteration but does not decrement it automatically.
If of_node_put() is not called manually, the reference count will never
reach zero, resulting in a memory leak of the node.
Best regards,
Ai Chao
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 2/6] ASoC: aoa: Use helper function for_each_child_of_node_scoped()
2025-05-26 8:20 ` Ai Chao
@ 2025-05-26 8:21 ` Johannes Berg
2025-05-30 9:30 ` Ai Chao
2025-05-28 19:23 ` Dmitry Baryshkov
1 sibling, 1 reply; 19+ messages in thread
From: Johannes Berg @ 2025-05-26 8:21 UTC (permalink / raw)
To: Ai Chao, perex, tiwai, kuninori.morimoto.gx, lgirdwood, broonie,
jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm
On Mon, 2025-05-26 at 16:20 +0800, Ai Chao wrote:
> Hi Johannes:
> > > Hi Johannes:
> > >
> > > > > "simplifies the code" is no need to callof_node_put() .
> > > > Fair. Except that's not what you _actually_ changed here. Like I said,
> > > > either it's buggy before or after.
> > > >
> > > In the function i2sbus_probe, it not return a struct device_node, so , I
> > > think function for_each_child_of_node_scoped is better than
> > > for_each_child_of_node.
> > You still haven't explained why it's even correct.
> >
> > johannes
>
> The for_each_child_of_node() function is used to iterate over all child
> nodes of a device tree node.
> During each iteration, it retrieves a pointer to the child node via
> of_get_next_child() and automatically increments the node's reference
> count (of_node_get()).
> Each call to of_get_next_child() increases the reference count
> (refcount) of the returned child node, ensuring that the node is not
> freed while in use.
> for_each_child_of_node() increments the child node's reference count in
> each iteration but does not decrement it automatically.
> If of_node_put() is not called manually, the reference count will never
> reach zero, resulting in a memory leak of the node.
Yes, good! Now show that you can apply what you've learned to the
specific code (and changes) at hand.
johannes
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 2/6] ASoC: aoa: Use helper function for_each_child_of_node_scoped()
2025-05-23 10:51 ` Christophe Leroy
@ 2025-05-26 8:53 ` Ai Chao
0 siblings, 0 replies; 19+ messages in thread
From: Ai Chao @ 2025-05-26 8:53 UTC (permalink / raw)
To: Christophe Leroy, perex, tiwai, johannes, kuninori.morimoto.gx,
lgirdwood, broonie, jbrunet, neil.armstrong, khilman,
martin.blumenstingl, shengjiu.wang, Xiubo.Lee, festevam,
nicoleotsuka, shawnguo, s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm
Hi Christophe:
>> 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.
>
>> }
>> + of_node_put(sound);
>> +
The for_each_child_of_node() function is used to iterate over all child
nodes of a device tree node. During each iteration, it retrieves a
pointer to the child node via of_get_next_child() and automatically
increments the node's reference count (of_node_get()). Each call to
of_get_next_child() increases the reference count (refcount) of the
returned child node, ensuring that the node is not freed while in use.
for_each_child_of_node() increments the child node's reference count in
each iteration but does not decrement it automatically.
If of_node_put() is not called manually, the reference count will never
reach zero, resulting in a memory leak of the node.
In function i2sbus_add_dev, it used device_node out of
for_each_child_of_node(){}, it need to add a new call to
of_node_put(sound) to reference count.
In function i2cbus_probe, it used device_node in
for_each_child_of_node(){}, used for_each_child_of_node_scoped() is
better than for_each_child_of_node().
Best regards,
Ai Chao
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 2/6] ASoC: aoa: Use helper function for_each_child_of_node_scoped()
2025-05-26 8:20 ` Ai Chao
2025-05-26 8:21 ` Johannes Berg
@ 2025-05-28 19:23 ` Dmitry Baryshkov
1 sibling, 0 replies; 19+ messages in thread
From: Dmitry Baryshkov @ 2025-05-28 19:23 UTC (permalink / raw)
To: Ai Chao
Cc: Johannes Berg, perex, tiwai, kuninori.morimoto.gx, lgirdwood,
broonie, jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla, linux-sound, linux-kernel,
linuxppc-dev, linux-renesas-soc, linux-arm-kernel, linux-amlogic,
imx, kernel, linux-arm-msm
On Mon, May 26, 2025 at 04:20:37PM +0800, Ai Chao wrote:
>
> Hi Johannes:
> > > Hi Johannes:
> > >
> > > > > "simplifies the code" is no need to callof_node_put() .
> > > > Fair. Except that's not what you _actually_ changed here. Like I said,
> > > > either it's buggy before or after.
> > > >
> > > In the function i2sbus_probe, it not return a struct device_node, so , I
> > > think function for_each_child_of_node_scoped is better than
> > > for_each_child_of_node.
> > You still haven't explained why it's even correct.
> >
> > johannes
>
> The for_each_child_of_node() function is used to iterate over all child
> nodes of a device tree node.
> During each iteration, it retrieves a pointer to the child node via
> of_get_next_child() and automatically increments the node's reference count
> (of_node_get()).
This is not complete story, you missed the second part of it.
> Each call to of_get_next_child() increases the reference count (refcount) of
> the returned child node, ensuring that the node is not freed while in use.
> for_each_child_of_node() increments the child node's reference count in each
> iteration but does not decrement it automatically.
> If of_node_put() is not called manually, the reference count will never
> reach zero, resulting in a memory leak of the node.
>
> Best regards,
> Ai Chao
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v2 2/6] ASoC: aoa: Use helper function for_each_child_of_node_scoped()
2025-05-26 8:21 ` Johannes Berg
@ 2025-05-30 9:30 ` Ai Chao
0 siblings, 0 replies; 19+ messages in thread
From: Ai Chao @ 2025-05-30 9:30 UTC (permalink / raw)
To: Johannes Berg, perex, tiwai, kuninori.morimoto.gx, lgirdwood,
broonie, jbrunet, neil.armstrong, khilman, martin.blumenstingl,
shengjiu.wang, Xiubo.Lee, festevam, nicoleotsuka, shawnguo,
s.hauer, srinivas.kandagatla
Cc: linux-sound, linux-kernel, linuxppc-dev, linux-renesas-soc,
linux-arm-kernel, linux-amlogic, imx, kernel, linux-arm-msm
Hi Johannes:
Thanks for your feedback. I will drop it.
> On Mon, 2025-05-26 at 16:20 +0800, Ai Chao wrote:
>> Hi Johannes:
>>>> for_each_child_of_node.
>>> You still haven't explained why it's even correct.
>>>
>>> johannes
>> The for_each_child_of_node() function is used to iterate over all child
>> nodes of a device tree node.
>> During each iteration, it retrieves a pointer to the child node via
>> of_get_next_child() and automatically increments the node's reference
>> count (of_node_get()).
>> Each call to of_get_next_child() increases the reference count
>> (refcount) of the returned child node, ensuring that the node is not
>> freed while in use.
>> for_each_child_of_node() increments the child node's reference count in
>> each iteration but does not decrement it automatically.
>> If of_node_put() is not called manually, the reference count will never
>> reach zero, resulting in a memory leak of the node.
> Yes, good! Now show that you can apply what you've learned to the
> specific code (and changes) at hand.
>
> johannes
--
Best regards,
Ai Chao
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2025-05-30 9:40 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-22 5:02 [PATCH v2 0/6] Use helper function for_each_child_of_node_scoped() Ai Chao
2025-05-22 5:02 ` [PATCH v2 1/6] ASoC: ppc: " Ai Chao
2025-05-22 10:00 ` Mark Brown
2025-05-22 5:02 ` [PATCH v2 2/6] ASoC: aoa: " Ai Chao
2025-05-22 10:04 ` Johannes Berg
2025-05-23 10:51 ` Christophe Leroy
2025-05-26 8:53 ` Ai Chao
2025-05-22 5:02 ` [PATCH v2 3/6] ASoC: renesas: " Ai Chao
2025-05-22 5:02 ` [PATCH v2 4/6] ASoC: meson: " Ai Chao
2025-05-22 5:02 ` [PATCH v2 5/6] ASoC: imx-card: " Ai Chao
2025-05-22 5:02 ` [PATCH v2 6/6] ASoC: qcom: " Ai Chao
2025-05-22 12:37 ` Dmitry Baryshkov
[not found] <2aq0nyvyf7t-2aq4hsc7kp6@nsmail7.0.0--kylin--1>
2025-05-23 10:40 ` [PATCH v2 2/6] ASoC: aoa: " Johannes Berg
2025-05-26 8:12 ` Ai Chao
2025-05-26 8:13 ` Johannes Berg
2025-05-26 8:20 ` Ai Chao
2025-05-26 8:21 ` Johannes Berg
2025-05-30 9:30 ` Ai Chao
2025-05-28 19:23 ` Dmitry Baryshkov
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).