ASoC: use scoped OF node handling in manual cleanup paths

Cássio Gabriel <cassiogabrielcontato@gmail.com> says:

Some ASoC drivers still manually release child OF nodes
when leaving child-node iteration loops early.

Convert these focused cases to scoped OF node cleanup
so early returns and normal loop exits keep the same node
lifetime handling without explicit of_node_put() calls.

- Patch 1 updates qcom_snd_parse_of() to use
  for_each_available_child_of_node_scoped() for link nodes and
  __free(device_node) for temporary cpu/platform/codec child nodes.
- Patch 2 updates fsl_qmc_audio to use
  for_each_available_child_of_node_scoped() for DAI child-node parsing.
- Patch 3 updates cygnus-ssp to use
  for_each_available_child_of_node_scoped() for SSP child-node parsing.

Link: https://patch.msgid.link/20260608-asoc-of-node-scoped-cleanup-v1-0-9e3ac518dc2e@gmail.com
This commit is contained in:
Mark Brown 2026-06-12 16:12:13 +01:00
commit 7165d138c6
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
3 changed files with 21 additions and 43 deletions

View File

@ -1298,7 +1298,6 @@ static int audio_clk_init(struct platform_device *pdev,
static int cygnus_ssp_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *child_node;
struct cygnus_audio *cygaud;
int err;
int node_count;
@ -1331,16 +1330,15 @@ static int cygnus_ssp_probe(struct platform_device *pdev)
active_port_count = 0;
for_each_available_child_of_node(pdev->dev.of_node, child_node) {
for_each_available_child_of_node_scoped(pdev->dev.of_node, child_node) {
err = parse_ssp_child_node(pdev, child_node, cygaud,
&cygnus_ssp_dai[active_port_count]);
/* negative is err, 0 is active and good, 1 is disabled */
if (err < 0) {
of_node_put(child_node);
if (err < 0)
return err;
}
else if (!err) {
if (!err) {
dev_dbg(dev, "Activating DAI: %s\n",
cygnus_ssp_dai[active_port_count].name);
active_port_count++;

View File

@ -905,7 +905,6 @@ static int qmc_audio_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
struct qmc_audio *qmc_audio;
struct device_node *child;
unsigned int i;
int ret;
@ -931,14 +930,12 @@ static int qmc_audio_probe(struct platform_device *pdev)
}
i = 0;
for_each_available_child_of_node(np, child) {
for_each_available_child_of_node_scoped(np, child) {
ret = qmc_audio_dai_parse(qmc_audio, child,
qmc_audio->dais + i,
qmc_audio->dai_drivers + i);
if (ret) {
of_node_put(child);
if (ret)
return ret;
}
i++;
}

View File

@ -25,10 +25,6 @@ static const struct snd_soc_dapm_widget qcom_jack_snd_widgets[] = {
int qcom_snd_parse_of(struct snd_soc_card *card)
{
struct device_node *np;
struct device_node *codec = NULL;
struct device_node *platform = NULL;
struct device_node *cpu = NULL;
struct device *dev = card->dev;
struct snd_soc_dai_link *link;
struct of_phandle_args args;
@ -82,12 +78,10 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
card->num_links = num_links;
link = card->dai_link;
for_each_available_child_of_node(dev->of_node, np) {
for_each_available_child_of_node_scoped(dev->of_node, np) {
dlc = devm_kcalloc(dev, 2, sizeof(*dlc), GFP_KERNEL);
if (!dlc) {
ret = -ENOMEM;
goto err_put_np;
}
if (!dlc)
return -ENOMEM;
link->cpus = &dlc[0];
link->platforms = &dlc[1];
@ -98,32 +92,33 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
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 ret;
}
cpu = of_get_child_by_name(np, "cpu");
platform = of_get_child_by_name(np, "platform");
codec = of_get_child_by_name(np, "codec");
struct device_node *cpu __free(device_node) =
of_get_child_by_name(np, "cpu");
struct device_node *platform __free(device_node) =
of_get_child_by_name(np, "platform");
struct device_node *codec __free(device_node) =
of_get_child_by_name(np, "codec");
if (!cpu) {
dev_err(dev, "%s: Can't find cpu DT node\n", link->name);
ret = -EINVAL;
goto err;
return -EINVAL;
}
ret = snd_soc_of_get_dlc(cpu, &args, link->cpus, 0);
if (ret) {
dev_err_probe(card->dev, ret,
"%s: error getting cpu dai name\n", link->name);
goto err;
return ret;
}
link->id = args.args[0];
if (link->id >= LPASS_MAX_PORT) {
dev_err(dev, "%s: Invalid cpu dai id %d\n", link->name, link->id);
ret = -EINVAL;
goto err;
return -EINVAL;
}
if (platform) {
@ -132,8 +127,7 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
0);
if (!link->platforms->of_node) {
dev_err(card->dev, "%s: platform dai not found\n", link->name);
ret = -EINVAL;
goto err;
return -EINVAL;
}
} else {
link->platforms->of_node = link->cpus->of_node;
@ -144,7 +138,7 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
if (ret < 0) {
dev_err_probe(card->dev, ret,
"%s: codec dai not found\n", link->name);
goto err;
return ret;
}
if (platform) {
@ -167,10 +161,6 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
link->stream_name = link->name;
link++;
of_node_put(cpu);
of_node_put(codec);
of_node_put(platform);
}
if (!card->dapm_widgets) {
@ -179,13 +169,6 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
}
return 0;
err:
of_node_put(cpu);
of_node_put(codec);
of_node_put(platform);
err_put_np:
of_node_put(np);
return ret;
}
EXPORT_SYMBOL_GPL(qcom_snd_parse_of);