Commit 5ba06fc9 authored by Mark Brown's avatar Mark Brown

ASoC: dapm: Refactor snd_soc_dapm_new_widget() to return the widget

Let the caller fiddle with the widget after we're done in order to
facilitate further refactoring.
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: default avatarLiam Girdwood <lrg@ti.com>
parent ce0e9f0e
...@@ -2698,24 +2698,16 @@ int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol, ...@@ -2698,24 +2698,16 @@ int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
} }
EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch); EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
/** static struct snd_soc_dapm_widget *
* snd_soc_dapm_new_control - create new dapm control snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
* @dapm: DAPM context const struct snd_soc_dapm_widget *widget)
* @widget: widget template
*
* Creates a new dapm control based upon the template.
*
* Returns 0 for success else error.
*/
static int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
const struct snd_soc_dapm_widget *widget)
{ {
struct snd_soc_dapm_widget *w; struct snd_soc_dapm_widget *w;
size_t name_len; size_t name_len;
int ret; int ret;
if ((w = dapm_cnew_widget(widget)) == NULL) if ((w = dapm_cnew_widget(widget)) == NULL)
return -ENOMEM; return NULL;
switch (w->id) { switch (w->id) {
case snd_soc_dapm_regulator_supply: case snd_soc_dapm_regulator_supply:
...@@ -2724,7 +2716,7 @@ static int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, ...@@ -2724,7 +2716,7 @@ static int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
ret = PTR_ERR(w->priv); ret = PTR_ERR(w->priv);
dev_err(dapm->dev, "Failed to request %s: %d\n", dev_err(dapm->dev, "Failed to request %s: %d\n",
w->name, ret); w->name, ret);
return ret; return NULL;
} }
break; break;
default: default:
...@@ -2737,7 +2729,7 @@ static int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, ...@@ -2737,7 +2729,7 @@ static int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
w->name = kmalloc(name_len, GFP_KERNEL); w->name = kmalloc(name_len, GFP_KERNEL);
if (w->name == NULL) { if (w->name == NULL) {
kfree(w); kfree(w);
return -ENOMEM; return NULL;
} }
if (dapm->codec && dapm->codec->name_prefix) if (dapm->codec && dapm->codec->name_prefix)
snprintf(w->name, name_len, "%s %s", snprintf(w->name, name_len, "%s %s",
...@@ -2796,7 +2788,7 @@ static int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, ...@@ -2796,7 +2788,7 @@ static int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
/* machine layer set ups unconnected pins and insertions */ /* machine layer set ups unconnected pins and insertions */
w->connected = 1; w->connected = 1;
return 0; return w;
} }
/** /**
...@@ -2813,15 +2805,16 @@ int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm, ...@@ -2813,15 +2805,16 @@ int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
const struct snd_soc_dapm_widget *widget, const struct snd_soc_dapm_widget *widget,
int num) int num)
{ {
int i, ret; struct snd_soc_dapm_widget *w;
int i;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
ret = snd_soc_dapm_new_control(dapm, widget); w = snd_soc_dapm_new_control(dapm, widget);
if (ret < 0) { if (!w) {
dev_err(dapm->dev, dev_err(dapm->dev,
"ASoC: Failed to create DAPM control %s: %d\n", "ASoC: Failed to create DAPM control %s\n",
widget->name, ret); widget->name);
return ret; return -ENOMEM;
} }
widget++; widget++;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment