ASoC: dapm: Move error handling to snd_soc_dapm_new_control_unlocked

Currently DAPM has a lot of similar code to handle errors from
snd_soc_dapm_new_control_unlocked, and much of this code does
not really accurately reflect what the function returns.

Firstly, most places will check for a return value of
-EPROBE_DEFER and silence any error messages in that case. The
one notable exception here being dapm_kcontrol_data_alloc
which does currently print any error messages in the case
of snd_soc_dapm_new_control_unlocked returning NULL or an
error. Additionally the error prints being silenced in these
case are redundant as snd_soc_dapm_new_control_unlocked can
only return -EPROBE_DEFER or NULL when failing.

Secondly, most places will treat a return value of NULL as
an -ENOMEM.  This is not correct either since any error except
EPROBE_DEFER will cause a return value of NULL from
snd_soc_dapm_new_control_unlocked.

Centralise this handling and the error messages within
snd_soc_dapm_new_control_unlocked and update the callers
to simply check IS_ERR and return. Note that this update is
slightly simpler in the case of dapm_kcontrol_data_alloc where
that is fairly close to the handling that was already in place.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Charles Keepax 2018-09-05 15:20:58 +01:00 committed by Mark Brown
parent 0b7990e389
commit 3bbf5d34fd
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
2 changed files with 19 additions and 110 deletions

View File

@ -364,10 +364,6 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
ret = PTR_ERR(data->widget); ret = PTR_ERR(data->widget);
goto err_data; goto err_data;
} }
if (!data->widget) {
ret = -ENOMEM;
goto err_data;
}
} }
break; break;
case snd_soc_dapm_demux: case snd_soc_dapm_demux:
@ -402,10 +398,6 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
ret = PTR_ERR(data->widget); ret = PTR_ERR(data->widget);
goto err_data; goto err_data;
} }
if (!data->widget) {
ret = -ENOMEM;
goto err_data;
}
snd_soc_dapm_add_path(widget->dapm, data->widget, snd_soc_dapm_add_path(widget->dapm, data->widget,
widget, NULL, NULL); widget, NULL, NULL);
@ -3433,23 +3425,8 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
w = snd_soc_dapm_new_control_unlocked(dapm, widget); w = snd_soc_dapm_new_control_unlocked(dapm, widget);
/* Do not nag about probe deferrals */
if (IS_ERR(w)) {
int ret = PTR_ERR(w);
if (ret != -EPROBE_DEFER)
dev_err(dapm->dev,
"ASoC: Failed to create DAPM control %s (%d)\n",
widget->name, ret);
goto out_unlock;
}
if (!w)
dev_err(dapm->dev,
"ASoC: Failed to create DAPM control %s\n",
widget->name);
out_unlock:
mutex_unlock(&dapm->card->dapm_mutex); mutex_unlock(&dapm->card->dapm_mutex);
return w; return w;
} }
EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control); EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
@ -3464,24 +3441,20 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
int ret; int ret;
if ((w = dapm_cnew_widget(widget)) == NULL) if ((w = dapm_cnew_widget(widget)) == NULL)
return NULL; return ERR_PTR(-ENOMEM);
switch (w->id) { switch (w->id) {
case snd_soc_dapm_regulator_supply: case snd_soc_dapm_regulator_supply:
w->regulator = devm_regulator_get(dapm->dev, w->name); w->regulator = devm_regulator_get(dapm->dev, w->name);
if (IS_ERR(w->regulator)) { if (IS_ERR(w->regulator)) {
ret = PTR_ERR(w->regulator); ret = PTR_ERR(w->regulator);
if (ret == -EPROBE_DEFER) goto request_failed;
return ERR_PTR(ret);
dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n",
w->name, ret);
return NULL;
} }
if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) { if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) {
ret = regulator_allow_bypass(w->regulator, true); ret = regulator_allow_bypass(w->regulator, true);
if (ret != 0) if (ret != 0)
dev_warn(w->dapm->dev, dev_warn(dapm->dev,
"ASoC: Failed to bypass %s: %d\n", "ASoC: Failed to bypass %s: %d\n",
w->name, ret); w->name, ret);
} }
@ -3490,22 +3463,14 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
w->pinctrl = devm_pinctrl_get(dapm->dev); w->pinctrl = devm_pinctrl_get(dapm->dev);
if (IS_ERR(w->pinctrl)) { if (IS_ERR(w->pinctrl)) {
ret = PTR_ERR(w->pinctrl); ret = PTR_ERR(w->pinctrl);
if (ret == -EPROBE_DEFER) goto request_failed;
return ERR_PTR(ret);
dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n",
w->name, ret);
return NULL;
} }
break; break;
case snd_soc_dapm_clock_supply: case snd_soc_dapm_clock_supply:
w->clk = devm_clk_get(dapm->dev, w->name); w->clk = devm_clk_get(dapm->dev, w->name);
if (IS_ERR(w->clk)) { if (IS_ERR(w->clk)) {
ret = PTR_ERR(w->clk); ret = PTR_ERR(w->clk);
if (ret == -EPROBE_DEFER) goto request_failed;
return ERR_PTR(ret);
dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n",
w->name, ret);
return NULL;
} }
break; break;
default: default:
@ -3519,7 +3484,7 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
w->name = kstrdup_const(widget->name, GFP_KERNEL); w->name = kstrdup_const(widget->name, GFP_KERNEL);
if (w->name == NULL) { if (w->name == NULL) {
kfree(w); kfree(w);
return NULL; return ERR_PTR(-ENOMEM);
} }
switch (w->id) { switch (w->id) {
@ -3596,6 +3561,13 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
/* machine layer sets up unconnected pins and insertions */ /* machine layer sets up unconnected pins and insertions */
w->connected = 1; w->connected = 1;
return w; return w;
request_failed:
if (ret != -EPROBE_DEFER)
dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n",
w->name, ret);
return ERR_PTR(ret);
} }
/** /**
@ -3621,19 +3593,6 @@ int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
w = snd_soc_dapm_new_control_unlocked(dapm, widget); w = snd_soc_dapm_new_control_unlocked(dapm, widget);
if (IS_ERR(w)) { if (IS_ERR(w)) {
ret = PTR_ERR(w); ret = PTR_ERR(w);
/* Do not nag about probe deferrals */
if (ret == -EPROBE_DEFER)
break;
dev_err(dapm->dev,
"ASoC: Failed to create DAPM control %s (%d)\n",
widget->name, ret);
break;
}
if (!w) {
dev_err(dapm->dev,
"ASoC: Failed to create DAPM control %s\n",
widget->name);
ret = -ENOMEM;
break; break;
} }
widget++; widget++;
@ -3944,21 +3903,8 @@ int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name); dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name);
w = snd_soc_dapm_new_control_unlocked(&card->dapm, &template); w = snd_soc_dapm_new_control_unlocked(&card->dapm, &template);
if (IS_ERR(w)) { if (IS_ERR(w))
ret = PTR_ERR(w);
/* Do not nag about probe deferrals */
if (ret != -EPROBE_DEFER)
dev_err(card->dev,
"ASoC: Failed to create %s widget (%d)\n",
link_name, ret);
goto outfree_kcontrol_news; goto outfree_kcontrol_news;
}
if (!w) {
dev_err(card->dev, "ASoC: Failed to create %s widget\n",
link_name);
ret = -ENOMEM;
goto outfree_kcontrol_news;
}
w->params = params; w->params = params;
w->num_params = num_params; w->num_params = num_params;
@ -3999,21 +3945,8 @@ int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
template.name); template.name);
w = snd_soc_dapm_new_control_unlocked(dapm, &template); w = snd_soc_dapm_new_control_unlocked(dapm, &template);
if (IS_ERR(w)) { if (IS_ERR(w))
int ret = PTR_ERR(w); return PTR_ERR(w);
/* Do not nag about probe deferrals */
if (ret != -EPROBE_DEFER)
dev_err(dapm->dev,
"ASoC: Failed to create %s widget (%d)\n",
dai->driver->playback.stream_name, ret);
return ret;
}
if (!w) {
dev_err(dapm->dev, "ASoC: Failed to create %s widget\n",
dai->driver->playback.stream_name);
return -ENOMEM;
}
w->priv = dai; w->priv = dai;
dai->playback_widget = w; dai->playback_widget = w;
@ -4028,21 +3961,8 @@ int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
template.name); template.name);
w = snd_soc_dapm_new_control_unlocked(dapm, &template); w = snd_soc_dapm_new_control_unlocked(dapm, &template);
if (IS_ERR(w)) { if (IS_ERR(w))
int ret = PTR_ERR(w); return PTR_ERR(w);
/* Do not nag about probe deferrals */
if (ret != -EPROBE_DEFER)
dev_err(dapm->dev,
"ASoC: Failed to create %s widget (%d)\n",
dai->driver->playback.stream_name, ret);
return ret;
}
if (!w) {
dev_err(dapm->dev, "ASoC: Failed to create %s widget\n",
dai->driver->capture.stream_name);
return -ENOMEM;
}
w->priv = dai; w->priv = dai;
dai->capture_widget = w; dai->capture_widget = w;

View File

@ -1565,17 +1565,6 @@ widget:
widget = snd_soc_dapm_new_control_unlocked(dapm, &template); widget = snd_soc_dapm_new_control_unlocked(dapm, &template);
if (IS_ERR(widget)) { if (IS_ERR(widget)) {
ret = PTR_ERR(widget); ret = PTR_ERR(widget);
/* Do not nag about probe deferrals */
if (ret != -EPROBE_DEFER)
dev_err(tplg->dev,
"ASoC: failed to create widget %s controls (%d)\n",
w->name, ret);
goto hdr_err;
}
if (widget == NULL) {
dev_err(tplg->dev, "ASoC: failed to create widget %s controls\n",
w->name);
ret = -ENOMEM;
goto hdr_err; goto hdr_err;
} }