Commit 5a7c2e96 authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: soc-dapm.c: cleanup snd_soc_dapm_new_dai()

snd_soc_dapm_new_dai() setups local variable "template" at (X) and (Y),
which is used at (Z). But these are difficult to read.

	static struct snd_soc_dapm_widget * snd_soc_dapm_new_dai()
	{
		...

 ^		template.reg = ...
 |		template.id = ...
(X)		template.name = ...
 |		template.event = ...
 |		template.event_flags = ...
 v		template.kcontrol_news = ...

		if (rtd->dai_link->num_params > 1) {
			...
 ^			template.num_kcontrols = ...
(Y)			template.kcontrol_news = ...
 v			...
		}

		...
(Z)		w = snd_soc_dapm_new_control_unlocked(..., &template);

	}

And this function has error message, but not for all cases.
This patch (1) setups "template" in one place, and indicate error message
for all cases. This patch cleanup the code, but nothing changed for
meaning.
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: default avatarAmadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
Link: https://lore.kernel.org/r/871qr4tzro.wl-kuninori.morimoto.gx@renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 9941ba4b
......@@ -4131,56 +4131,53 @@ snd_soc_dapm_new_dai(struct snd_soc_card *card,
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
struct snd_soc_dapm_widget template;
struct snd_soc_dapm_widget *w;
const struct snd_kcontrol_new *kcontrol_news;
int num_kcontrols;
const char **w_param_text;
unsigned long private_value = 0;
char *link_name;
int ret;
int ret = -ENOMEM;
link_name = devm_kasprintf(card->dev, GFP_KERNEL, "%s-%s",
rtd->dai_link->name, id);
if (!link_name)
return ERR_PTR(-ENOMEM);
memset(&template, 0, sizeof(template));
template.reg = SND_SOC_NOPM;
template.id = snd_soc_dapm_dai_link;
template.name = link_name;
template.event = snd_soc_dai_link_event;
template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD;
template.kcontrol_news = NULL;
goto name_fail;
/* allocate memory for control, only in case of multiple configs */
w_param_text = NULL;
kcontrol_news = NULL;
num_kcontrols = 0;
if (rtd->dai_link->num_params > 1) {
w_param_text = devm_kcalloc(card->dev,
rtd->dai_link->num_params,
sizeof(char *), GFP_KERNEL);
if (!w_param_text) {
ret = -ENOMEM;
if (!w_param_text)
goto param_fail;
}
template.num_kcontrols = 1;
template.kcontrol_news =
snd_soc_dapm_alloc_kcontrol(card,
link_name,
rtd->dai_link->params,
rtd->dai_link->num_params,
w_param_text, &private_value);
if (!template.kcontrol_news) {
ret = -ENOMEM;
num_kcontrols = 1;
kcontrol_news = snd_soc_dapm_alloc_kcontrol(card, link_name,
rtd->dai_link->params,
rtd->dai_link->num_params,
w_param_text, &private_value);
if (!kcontrol_news)
goto param_fail;
}
} else {
w_param_text = NULL;
}
memset(&template, 0, sizeof(template));
template.reg = SND_SOC_NOPM;
template.id = snd_soc_dapm_dai_link;
template.name = link_name;
template.event = snd_soc_dai_link_event;
template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD;
template.kcontrol_news = kcontrol_news;
template.num_kcontrols = num_kcontrols;
dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name);
w = snd_soc_dapm_new_control_unlocked(&card->dapm, &template);
if (IS_ERR(w)) {
ret = PTR_ERR(w);
dev_err(rtd->dev, "ASoC: Failed to create %s widget: %d\n",
link_name, ret);
goto outfree_kcontrol_news;
}
......@@ -4194,6 +4191,9 @@ snd_soc_dapm_new_dai(struct snd_soc_card *card,
rtd->dai_link->num_params, w_param_text);
param_fail:
devm_kfree(card->dev, link_name);
name_fail:
dev_err(rtd->dev, "ASoC: Failed to create %s-%s widget: %d\n",
rtd->dai_link->name, id, ret);
return ERR_PTR(ret);
}
......
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