Skip to content

Commit 7165d13

Browse files
committed
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
2 parents c429fbe + 9741aad commit 7165d13

3 files changed

Lines changed: 21 additions & 43 deletions

File tree

sound/soc/bcm/cygnus-ssp.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,6 @@ static int audio_clk_init(struct platform_device *pdev,
12981298
static int cygnus_ssp_probe(struct platform_device *pdev)
12991299
{
13001300
struct device *dev = &pdev->dev;
1301-
struct device_node *child_node;
13021301
struct cygnus_audio *cygaud;
13031302
int err;
13041303
int node_count;
@@ -1331,16 +1330,15 @@ static int cygnus_ssp_probe(struct platform_device *pdev)
13311330

13321331
active_port_count = 0;
13331332

1334-
for_each_available_child_of_node(pdev->dev.of_node, child_node) {
1333+
for_each_available_child_of_node_scoped(pdev->dev.of_node, child_node) {
13351334
err = parse_ssp_child_node(pdev, child_node, cygaud,
13361335
&cygnus_ssp_dai[active_port_count]);
13371336

13381337
/* negative is err, 0 is active and good, 1 is disabled */
1339-
if (err < 0) {
1340-
of_node_put(child_node);
1338+
if (err < 0)
13411339
return err;
1342-
}
1343-
else if (!err) {
1340+
1341+
if (!err) {
13441342
dev_dbg(dev, "Activating DAI: %s\n",
13451343
cygnus_ssp_dai[active_port_count].name);
13461344
active_port_count++;

sound/soc/fsl/fsl_qmc_audio.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,6 @@ static int qmc_audio_probe(struct platform_device *pdev)
905905
{
906906
struct device_node *np = pdev->dev.of_node;
907907
struct qmc_audio *qmc_audio;
908-
struct device_node *child;
909908
unsigned int i;
910909
int ret;
911910

@@ -931,14 +930,12 @@ static int qmc_audio_probe(struct platform_device *pdev)
931930
}
932931

933932
i = 0;
934-
for_each_available_child_of_node(np, child) {
933+
for_each_available_child_of_node_scoped(np, child) {
935934
ret = qmc_audio_dai_parse(qmc_audio, child,
936935
qmc_audio->dais + i,
937936
qmc_audio->dai_drivers + i);
938-
if (ret) {
939-
of_node_put(child);
937+
if (ret)
940938
return ret;
941-
}
942939
i++;
943940
}
944941

sound/soc/qcom/common.c

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ static const struct snd_soc_dapm_widget qcom_jack_snd_widgets[] = {
2525

2626
int qcom_snd_parse_of(struct snd_soc_card *card)
2727
{
28-
struct device_node *np;
29-
struct device_node *codec = NULL;
30-
struct device_node *platform = NULL;
31-
struct device_node *cpu = NULL;
3228
struct device *dev = card->dev;
3329
struct snd_soc_dai_link *link;
3430
struct of_phandle_args args;
@@ -82,12 +78,10 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
8278
card->num_links = num_links;
8379
link = card->dai_link;
8480

85-
for_each_available_child_of_node(dev->of_node, np) {
81+
for_each_available_child_of_node_scoped(dev->of_node, np) {
8682
dlc = devm_kcalloc(dev, 2, sizeof(*dlc), GFP_KERNEL);
87-
if (!dlc) {
88-
ret = -ENOMEM;
89-
goto err_put_np;
90-
}
83+
if (!dlc)
84+
return -ENOMEM;
9185

9286
link->cpus = &dlc[0];
9387
link->platforms = &dlc[1];
@@ -98,32 +92,33 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
9892
ret = of_property_read_string(np, "link-name", &link->name);
9993
if (ret) {
10094
dev_err(card->dev, "error getting codec dai_link name\n");
101-
goto err_put_np;
95+
return ret;
10296
}
10397

104-
cpu = of_get_child_by_name(np, "cpu");
105-
platform = of_get_child_by_name(np, "platform");
106-
codec = of_get_child_by_name(np, "codec");
98+
struct device_node *cpu __free(device_node) =
99+
of_get_child_by_name(np, "cpu");
100+
struct device_node *platform __free(device_node) =
101+
of_get_child_by_name(np, "platform");
102+
struct device_node *codec __free(device_node) =
103+
of_get_child_by_name(np, "codec");
107104

108105
if (!cpu) {
109106
dev_err(dev, "%s: Can't find cpu DT node\n", link->name);
110-
ret = -EINVAL;
111-
goto err;
107+
return -EINVAL;
112108
}
113109

114110
ret = snd_soc_of_get_dlc(cpu, &args, link->cpus, 0);
115111
if (ret) {
116112
dev_err_probe(card->dev, ret,
117113
"%s: error getting cpu dai name\n", link->name);
118-
goto err;
114+
return ret;
119115
}
120116

121117
link->id = args.args[0];
122118

123119
if (link->id >= LPASS_MAX_PORT) {
124120
dev_err(dev, "%s: Invalid cpu dai id %d\n", link->name, link->id);
125-
ret = -EINVAL;
126-
goto err;
121+
return -EINVAL;
127122
}
128123

129124
if (platform) {
@@ -132,8 +127,7 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
132127
0);
133128
if (!link->platforms->of_node) {
134129
dev_err(card->dev, "%s: platform dai not found\n", link->name);
135-
ret = -EINVAL;
136-
goto err;
130+
return -EINVAL;
137131
}
138132
} else {
139133
link->platforms->of_node = link->cpus->of_node;
@@ -144,7 +138,7 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
144138
if (ret < 0) {
145139
dev_err_probe(card->dev, ret,
146140
"%s: codec dai not found\n", link->name);
147-
goto err;
141+
return ret;
148142
}
149143

150144
if (platform) {
@@ -167,10 +161,6 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
167161

168162
link->stream_name = link->name;
169163
link++;
170-
171-
of_node_put(cpu);
172-
of_node_put(codec);
173-
of_node_put(platform);
174164
}
175165

176166
if (!card->dapm_widgets) {
@@ -179,13 +169,6 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
179169
}
180170

181171
return 0;
182-
err:
183-
of_node_put(cpu);
184-
of_node_put(codec);
185-
of_node_put(platform);
186-
err_put_np:
187-
of_node_put(np);
188-
return ret;
189172
}
190173
EXPORT_SYMBOL_GPL(qcom_snd_parse_of);
191174

0 commit comments

Comments
 (0)