ASoC: soc-pcm: add soc_pcm_components_open()

soc-pcm.c has soc_pcm_components_close() but not have its open()
side function. This kind of unbalance function is very unreadable.

And, current error handling is not correct.
Because it is using for_each_rtdcom() loop, we need to call
soc_pcm_components_close() anyway even though
CPU DAI .startup() failed.

This patch adds soc_pcm_components_open(), and fixup error
handling issue.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Kuninori Morimoto 2019-05-13 16:08:33 +09:00 committed by Mark Brown
parent 2371abdc08
commit e7ecfdb794
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
1 changed files with 40 additions and 23 deletions

View File

@ -446,6 +446,42 @@ static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream)
hw->rate_max = min_not_zero(hw->rate_max, rate_max);
}
static int soc_pcm_components_open(struct snd_pcm_substream *substream,
struct snd_soc_component **last)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_rtdcom_list *rtdcom;
struct snd_soc_component *component;
int ret = 0;
for_each_rtdcom(rtd, rtdcom) {
component = rtdcom->component;
*last = component;
if (!component->driver->ops ||
!component->driver->ops->open)
continue;
if (component->driver->module_get_upon_open &&
!try_module_get(component->dev->driver->owner)) {
dev_err(component->dev,
"ASoC: can't get module %s\n",
component->name);
return -ENODEV;
}
ret = component->driver->ops->open(substream);
if (ret < 0) {
dev_err(component->dev,
"ASoC: can't open component %s: %d\n",
component->name, ret);
return ret;
}
}
*last = NULL;
return 0;
}
static int soc_pcm_components_close(struct snd_pcm_substream *substream,
struct snd_soc_component *last)
{
@ -510,28 +546,9 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
}
}
for_each_rtdcom(rtd, rtdcom) {
component = rtdcom->component;
if (!component->driver->ops ||
!component->driver->ops->open)
continue;
if (component->driver->module_get_upon_open &&
!try_module_get(component->dev->driver->owner)) {
ret = -ENODEV;
goto module_err;
}
ret = component->driver->ops->open(substream);
if (ret < 0) {
dev_err(component->dev,
"ASoC: can't open component %s: %d\n",
component->name, ret);
goto component_err;
}
}
component = NULL;
ret = soc_pcm_components_open(substream, &component);
if (ret < 0)
goto component_err;
for_each_rtd_codec_dai(rtd, i, codec_dai) {
if (codec_dai->driver->ops->startup) {
@ -638,7 +655,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
component_err:
soc_pcm_components_close(substream, component);
module_err:
if (cpu_dai->driver->ops->shutdown)
cpu_dai->driver->ops->shutdown(substream, cpu_dai);
out: