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>
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 2dcc44c..74c7d38 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -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: