Skip to content

Commit e512e00

Browse files
moinejfbroonie
authored andcommitted
ASoC: simple-card: Fix the reference count of device nodes
The reference count of some device nodes is not correctly reset at end of card probe. Signed-off-by: Jean-Francois Moine <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 12ffa6f commit e512e00

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

sound/soc/generic/simple-card.c

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ asoc_simple_card_sub_parse_of(struct device_node *np,
105105
/* get dai->name */
106106
ret = snd_soc_of_get_dai_name(np, name);
107107
if (ret < 0)
108-
goto parse_error;
108+
return ret;
109109

110110
/* parse TDM slot */
111111
ret = snd_soc_of_parse_tdm_slot(np, &dai->slots, &dai->slot_width);
112112
if (ret)
113-
goto parse_error;
113+
return ret;
114114

115115
/*
116116
* bitclock-inversion, frame-inversion
@@ -130,7 +130,7 @@ asoc_simple_card_sub_parse_of(struct device_node *np,
130130
clk = of_clk_get(np, 0);
131131
if (IS_ERR(clk)) {
132132
ret = PTR_ERR(clk);
133-
goto parse_error;
133+
return ret;
134134
}
135135

136136
dai->sysclk = clk_get_rate(clk);
@@ -144,12 +144,7 @@ asoc_simple_card_sub_parse_of(struct device_node *np,
144144
dai->sysclk = clk_get_rate(clk);
145145
}
146146

147-
ret = 0;
148-
149-
parse_error:
150-
of_node_put(node);
151-
152-
return ret;
147+
return 0;
153148
}
154149

155150
static int asoc_simple_card_parse_of(struct device_node *node,
@@ -187,22 +182,26 @@ static int asoc_simple_card_parse_of(struct device_node *node,
187182
/* CPU sub-node */
188183
ret = -EINVAL;
189184
np = of_get_child_by_name(node, "simple-audio-card,cpu");
190-
if (np)
185+
if (np) {
191186
ret = asoc_simple_card_sub_parse_of(np, priv->daifmt,
192187
&priv->cpu_dai,
193188
&dai_link->cpu_of_node,
194189
&dai_link->cpu_dai_name);
190+
of_node_put(np);
191+
}
195192
if (ret < 0)
196193
return ret;
197194

198195
/* CODEC sub-node */
199196
ret = -EINVAL;
200197
np = of_get_child_by_name(node, "simple-audio-card,codec");
201-
if (np)
198+
if (np) {
202199
ret = asoc_simple_card_sub_parse_of(np, priv->daifmt,
203200
&priv->codec_dai,
204201
&dai_link->codec_of_node,
205202
&dai_link->codec_dai_name);
203+
of_node_put(np);
204+
}
206205
if (ret < 0)
207206
return ret;
208207

@@ -248,6 +247,27 @@ static int asoc_simple_card_parse_of(struct device_node *node,
248247
return 0;
249248
}
250249

250+
/* update the reference count of the devices nodes at end of probe */
251+
static int asoc_simple_card_unref(struct platform_device *pdev)
252+
{
253+
struct snd_soc_card *card = platform_get_drvdata(pdev);
254+
struct snd_soc_dai_link *dai_link;
255+
struct device_node *np;
256+
int num_links;
257+
258+
for (num_links = 0, dai_link = card->dai_link;
259+
num_links < card->num_links;
260+
num_links++, dai_link++) {
261+
np = (struct device_node *) dai_link->cpu_of_node;
262+
if (np)
263+
of_node_put(np);
264+
np = (struct device_node *) dai_link->codec_of_node;
265+
if (np)
266+
of_node_put(np);
267+
}
268+
return 0;
269+
}
270+
251271
static int asoc_simple_card_probe(struct platform_device *pdev)
252272
{
253273
struct simple_card_data *priv;
@@ -275,7 +295,7 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
275295
if (ret < 0) {
276296
if (ret != -EPROBE_DEFER)
277297
dev_err(dev, "parse error %d\n", ret);
278-
return ret;
298+
goto err;
279299
}
280300
} else {
281301
struct asoc_simple_card_info *cinfo;
@@ -318,7 +338,11 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
318338

319339
snd_soc_card_set_drvdata(&priv->snd_card, priv);
320340

321-
return devm_snd_soc_register_card(&pdev->dev, &priv->snd_card);
341+
ret = devm_snd_soc_register_card(&pdev->dev, &priv->snd_card);
342+
343+
err:
344+
asoc_simple_card_unref(pdev);
345+
return ret;
322346
}
323347

324348
static const struct of_device_id asoc_simple_of_match[] = {

0 commit comments

Comments
 (0)