Skip to content

Commit 37e1df8

Browse files
Linus Walleijbroonie
authored andcommitted
ASoC: dapm: handle probe deferrals
This starts to handle probe deferrals on regulators and clocks on the ASoC DAPM. I came to this patch after audio stopped working on Ux500 ages ago and I finally looked into it to see what is wrong. I had messages like this in the console since a while back: ab8500-codec.0: ASoC: Failed to request audioclk: -517 ab8500-codec.0: ASoC: Failed to create DAPM control audioclk ab8500-codec.0: Failed to create new controls -12 snd-soc-mop500.0: ASoC: failed to instantiate card -12 snd-soc-mop500.0: Error: snd_soc_register_card failed (-12)! snd-soc-mop500: probe of snd-soc-mop500.0 failed with error -12 Apparently because the widget table for the codec looks like this (sound/soc/codecs/ab8500-codec.c): static const struct snd_soc_dapm_widget ab8500_dapm_widgets[] = { /* Clocks */ SND_SOC_DAPM_CLOCK_SUPPLY("audioclk"), /* Regulators */ SND_SOC_DAPM_REGULATOR_SUPPLY("V-AUD", 0, 0), SND_SOC_DAPM_REGULATOR_SUPPLY("V-AMIC1", 0, 0), SND_SOC_DAPM_REGULATOR_SUPPLY("V-AMIC2", 0, 0), SND_SOC_DAPM_REGULATOR_SUPPLY("V-DMIC", 0, 0), So when we call snd_soc_register_codec() and any of these widgets get a deferred probe we do not get an -EPROBE_DEFER (-517) back as we should and instead we just fail. Apparently the code assumes that clocks and regulators must be available at this point and not defer. After this patch it rather looks like this: ab8500-codec.0: Failed to create new controls -517 snd-soc-mop500.0: ASoC: failed to instantiate card -517 snd-soc-mop500.0: Error: snd_soc_register_card failed (-517)! (...) abx500-clk.0: registered clocks for ab850x snd-soc-mop500.0: ab8500-codec-dai.0 <-> ux500-msp-i2s.1 mapping ok snd-soc-mop500.0: ab8500-codec-dai.1 <-> ux500-msp-i2s.3 mapping ok I'm pretty happy about the patch as it it, but I'm a bit uncertain on how to proceed: there are a lot of users of the external functions snd_soc_dapm_new_control() (111 sites) and that will now return an occassional error pointer, which is not handled in the calling sites. I want an indication from the maintainers whether I should just go in and augment all these call sites, or if deferred probe is frowned upon when it leads to this much overhead. Signed-off-by: Linus Walleij <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent a5de5b7 commit 37e1df8

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

sound/soc/soc-dapm.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
363363
snd_soc_dapm_new_control_unlocked(widget->dapm,
364364
&template);
365365
kfree(name);
366+
if (IS_ERR(data->widget)) {
367+
ret = PTR_ERR(data->widget);
368+
goto err_data;
369+
}
366370
if (!data->widget) {
367371
ret = -ENOMEM;
368372
goto err_data;
@@ -397,6 +401,10 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
397401
data->widget = snd_soc_dapm_new_control_unlocked(
398402
widget->dapm, &template);
399403
kfree(name);
404+
if (IS_ERR(data->widget)) {
405+
ret = PTR_ERR(data->widget);
406+
goto err_data;
407+
}
400408
if (!data->widget) {
401409
ret = -ENOMEM;
402410
goto err_data;
@@ -3403,11 +3411,22 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
34033411

34043412
mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
34053413
w = snd_soc_dapm_new_control_unlocked(dapm, widget);
3414+
/* Do not nag about probe deferrals */
3415+
if (IS_ERR(w)) {
3416+
int ret = PTR_ERR(w);
3417+
3418+
if (ret != -EPROBE_DEFER)
3419+
dev_err(dapm->dev,
3420+
"ASoC: Failed to create DAPM control %s (%d)\n",
3421+
widget->name, ret);
3422+
goto out_unlock;
3423+
}
34063424
if (!w)
34073425
dev_err(dapm->dev,
34083426
"ASoC: Failed to create DAPM control %s\n",
34093427
widget->name);
34103428

3429+
out_unlock:
34113430
mutex_unlock(&dapm->card->dapm_mutex);
34123431
return w;
34133432
}
@@ -3430,6 +3449,8 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
34303449
w->regulator = devm_regulator_get(dapm->dev, w->name);
34313450
if (IS_ERR(w->regulator)) {
34323451
ret = PTR_ERR(w->regulator);
3452+
if (ret == -EPROBE_DEFER)
3453+
return ERR_PTR(ret);
34333454
dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n",
34343455
w->name, ret);
34353456
return NULL;
@@ -3448,6 +3469,8 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
34483469
w->clk = devm_clk_get(dapm->dev, w->name);
34493470
if (IS_ERR(w->clk)) {
34503471
ret = PTR_ERR(w->clk);
3472+
if (ret == -EPROBE_DEFER)
3473+
return ERR_PTR(ret);
34513474
dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n",
34523475
w->name, ret);
34533476
return NULL;
@@ -3566,6 +3589,16 @@ int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
35663589
mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
35673590
for (i = 0; i < num; i++) {
35683591
w = snd_soc_dapm_new_control_unlocked(dapm, widget);
3592+
if (IS_ERR(w)) {
3593+
ret = PTR_ERR(w);
3594+
/* Do not nag about probe deferrals */
3595+
if (ret == -EPROBE_DEFER)
3596+
break;
3597+
dev_err(dapm->dev,
3598+
"ASoC: Failed to create DAPM control %s (%d)\n",
3599+
widget->name, ret);
3600+
break;
3601+
}
35693602
if (!w) {
35703603
dev_err(dapm->dev,
35713604
"ASoC: Failed to create DAPM control %s\n",
@@ -3842,6 +3875,15 @@ int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
38423875
dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name);
38433876

38443877
w = snd_soc_dapm_new_control_unlocked(&card->dapm, &template);
3878+
if (IS_ERR(w)) {
3879+
ret = PTR_ERR(w);
3880+
/* Do not nag about probe deferrals */
3881+
if (ret != -EPROBE_DEFER)
3882+
dev_err(card->dev,
3883+
"ASoC: Failed to create %s widget (%d)\n",
3884+
link_name, ret);
3885+
goto outfree_kcontrol_news;
3886+
}
38453887
if (!w) {
38463888
dev_err(card->dev, "ASoC: Failed to create %s widget\n",
38473889
link_name);

sound/soc/soc-topology.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,15 @@ static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg,
15561556
widget = snd_soc_dapm_new_control(dapm, &template);
15571557
else
15581558
widget = snd_soc_dapm_new_control_unlocked(dapm, &template);
1559+
if (IS_ERR(widget)) {
1560+
ret = PTR_ERR(widget);
1561+
/* Do not nag about probe deferrals */
1562+
if (ret != -EPROBE_DEFER)
1563+
dev_err(tplg->dev,
1564+
"ASoC: failed to create widget %s controls (%d)\n",
1565+
w->name, ret);
1566+
goto hdr_err;
1567+
}
15591568
if (widget == NULL) {
15601569
dev_err(tplg->dev, "ASoC: failed to create widget %s controls\n",
15611570
w->name);

0 commit comments

Comments
 (0)