[alsa-devel] [PATCH v2 5/7] ASoC: soc-pcm: goto error after trying all component open
Kuninori Morimoto
kuninori.morimoto.gx at renesas.com
Tue Jan 28 02:37:46 CET 2020
From: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
soc_pcm_components_open() might goto error process *during* opening
component loop.
In such case, fallback process need to care about operated/non-operated
component.
But, if it goto error process *after* loop even though error happen
during loop, it don't need to care about operated/non-operated.
In such case code can be more simple.
This patch do it. And this is prepare for soc_snd_open() cleanup
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
v1 -> v2
- indicate error from inside loop
sound/soc/soc-pcm.c | 37 +++++++++++++++----------------------
1 file changed, 15 insertions(+), 22 deletions(-)
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index cf7c31f..4add629 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -463,47 +463,40 @@ 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)
+static int soc_pcm_components_open(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_component *component;
int i, ret = 0;
for_each_rtd_components(rtd, i, component) {
- *last = component;
+ int r;
- ret = snd_soc_component_module_get_when_open(component);
- if (ret < 0) {
+ r = snd_soc_component_module_get_when_open(component);
+ if (r < 0)
dev_err(component->dev,
"ASoC: can't get module %s\n",
component->name);
- return ret;
- }
+ ret |= r;
- ret = snd_soc_component_open(component, substream);
- if (ret < 0) {
+ r = snd_soc_component_open(component, substream);
+ if (r < 0)
dev_err(component->dev,
"ASoC: can't open component %s: %d\n",
- component->name, ret);
- return ret;
- }
+ component->name, r);
+ ret |= r;
}
- *last = NULL;
- return 0;
+
+ return ret;
}
-static int soc_pcm_components_close(struct snd_pcm_substream *substream,
- struct snd_soc_component *last)
+static int soc_pcm_components_close(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_component *component;
int i, ret = 0;
for_each_rtd_components(rtd, i, component) {
- if (component == last)
- break;
-
ret |= snd_soc_component_close(component, substream);
snd_soc_component_module_put_when_close(component);
}
@@ -542,7 +535,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
goto out;
}
- ret = soc_pcm_components_open(substream, &component);
+ ret = soc_pcm_components_open(substream);
if (ret < 0)
goto component_err;
@@ -641,7 +634,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
snd_soc_dai_shutdown(codec_dai, substream);
component_err:
- soc_pcm_components_close(substream, component);
+ soc_pcm_components_close(substream);
snd_soc_dai_shutdown(cpu_dai, substream);
out:
@@ -695,7 +688,7 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
soc_rtd_shutdown(rtd, substream);
- soc_pcm_components_close(substream, NULL);
+ soc_pcm_components_close(substream);
snd_soc_dapm_stream_stop(rtd, substream->stream);
--
2.7.4
More information about the Alsa-devel
mailing list