ASoC: qcom: common: use scoped OF node handling

qcom_snd_parse_of() manually drops the link child node and the
cpu/platform/codec child nodes on error paths and at the end of each
iteration.

Use for_each_available_child_of_node_scoped() for the link node and
__free(device_node) for the named child nodes. This keeps the existing
ownership rules for DAI component phandle references, while removing the
manual cleanup labels from a path that has previously needed OF refcount
fixes.

Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com>
Link: https://patch.msgid.link/20260608-asoc-of-node-scoped-cleanup-v1-1-9e3ac518dc2e@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Cássio Gabriel 2026-06-08 10:39:11 -03:00 committed by Mark Brown
parent 4549871118
commit 22aed576ad
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0

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