From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
To: Mark Brown <broonie@kernel.org>
Cc: Linux-ALSA <alsa-devel@alsa-project.org>
Subject: [PATCH 2/5] ASoC: soc-dai: add mark for snd_soc_dai_compr_startup/shutdown()
Date: 19 Nov 2020 08:50:04 +0900 [thread overview]
Message-ID: <87mtze5iwp.wl-kuninori.morimoto.gx@renesas.com> (raw)
In-Reply-To: <87pn4a5ixl.wl-kuninori.morimoto.gx@renesas.com>
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
soc_compr_open() does rollback when failed (A),
but, it is almost same as soc_compr_free().
static int soc_compr_open(xxx)
{
...
if (ret < 0)
goto xxx_err;
...
return 0;
^ machine_err:
| ...
| out:
(A) ...
| pm_err:
| ...
v return ret;
}
The difference is
soc_compr_free() is for all dai/component/substream,
rollback is for succeeded part only.
This kind of duplicated code can be a hotbed of bugs,
thus, we want to share soc_compr_free() and rollback.
=> 1) snd_soc_dai_compr_startup/shutdown()
2) snd_soc_component_compr_open/free()
3) snd_soc_link_compr_startup/shutdown()
This patch is for 1) snd_soc_dai_compr_startup/shutdown(),
and adds new cstream mark.
It will mark cstream when startup() was suceeded.
If rollback happen *after* that, it will check rollback flag
and marked cstream.
It cares *previous* startup() only now,
but we might want to check *whole* marked cstream in the future.
This patch is using macro so that it can be easily adjust to it.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
include/sound/soc-dai.h | 4 +++-
sound/soc/soc-compress.c | 8 ++++----
sound/soc/soc-dai.c | 13 ++++++++++++-
3 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h
index 4bf759f025d2..6f54401d3de9 100644
--- a/include/sound/soc-dai.h
+++ b/include/sound/soc-dai.h
@@ -196,7 +196,8 @@ int snd_soc_pcm_dai_bespoke_trigger(struct snd_pcm_substream *substream,
int snd_soc_dai_compr_startup(struct snd_soc_dai *dai,
struct snd_compr_stream *cstream);
void snd_soc_dai_compr_shutdown(struct snd_soc_dai *dai,
- struct snd_compr_stream *cstream);
+ struct snd_compr_stream *cstream,
+ int rollback);
int snd_soc_dai_compr_trigger(struct snd_soc_dai *dai,
struct snd_compr_stream *cstream, int cmd);
int snd_soc_dai_compr_set_params(struct snd_soc_dai *dai,
@@ -400,6 +401,7 @@ struct snd_soc_dai {
/* function mark */
struct snd_pcm_substream *mark_startup;
struct snd_pcm_substream *mark_hw_params;
+ struct snd_compr_stream *mark_compr_startup;
/* bit field */
unsigned int probed:1;
diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
index 792c2aa1a3c0..d85b6b174006 100644
--- a/sound/soc/soc-compress.c
+++ b/sound/soc/soc-compress.c
@@ -45,7 +45,7 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
snd_soc_component_compr_free(cstream, NULL);
- snd_soc_dai_compr_shutdown(cpu_dai, cstream);
+ snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0);
snd_soc_dapm_stream_stop(rtd, stream);
@@ -91,7 +91,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
machine_err:
snd_soc_component_compr_free(cstream, component);
- snd_soc_dai_compr_shutdown(cpu_dai, cstream);
+ snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1);
out:
mutex_unlock(&rtd->card->pcm_mutex);
pm_err:
@@ -165,7 +165,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
machine_err:
snd_soc_component_compr_free(cstream, component);
open_err:
- snd_soc_dai_compr_shutdown(cpu_dai, cstream);
+ snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1);
out:
dpcm_path_put(&list);
be_err:
@@ -211,7 +211,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
snd_soc_component_compr_free(cstream, NULL);
- snd_soc_dai_compr_shutdown(cpu_dai, cstream);
+ snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0);
mutex_unlock(&fe->card->mutex);
return 0;
diff --git a/sound/soc/soc-dai.c b/sound/soc/soc-dai.c
index 2686a566649b..9afc6e8c3f9f 100644
--- a/sound/soc/soc-dai.c
+++ b/sound/soc/soc-dai.c
@@ -612,16 +612,27 @@ int snd_soc_dai_compr_startup(struct snd_soc_dai *dai,
dai->driver->cops->startup)
ret = dai->driver->cops->startup(cstream, dai);
+ /* mark cstream if succeeded */
+ if (ret == 0)
+ soc_dai_mark_push(dai, cstream, compr_startup);
+
return soc_dai_ret(dai, ret);
}
EXPORT_SYMBOL_GPL(snd_soc_dai_compr_startup);
void snd_soc_dai_compr_shutdown(struct snd_soc_dai *dai,
- struct snd_compr_stream *cstream)
+ struct snd_compr_stream *cstream,
+ int rollback)
{
+ if (rollback && !soc_dai_mark_match(dai, cstream, compr_startup))
+ return;
+
if (dai->driver->cops &&
dai->driver->cops->shutdown)
dai->driver->cops->shutdown(cstream, dai);
+
+ /* remove marked cstream */
+ soc_dai_mark_pop(dai, cstream, compr_startup);
}
EXPORT_SYMBOL_GPL(snd_soc_dai_compr_shutdown);
--
2.25.1
next prev parent reply other threads:[~2020-11-18 23:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-18 23:49 [PATCH 0/5] ASoC: merge soc_compr_open() rollback and soc_compr_free() Kuninori Morimoto
2020-11-18 23:49 ` [PATCH 1/5] ASoC: soc-compress: move soc_compr_free() next to soc_compr_open() Kuninori Morimoto
2020-11-18 23:50 ` Kuninori Morimoto [this message]
2020-11-18 23:50 ` [PATCH 3/5] ASoC: soc-component: add mark for snd_soc_component_compr_open/free() Kuninori Morimoto
2020-11-18 23:50 ` [PATCH 4/5] ASoC: soc-component: add mark for snd_soc_link_compr_startup/shutdown() Kuninori Morimoto
2020-11-18 23:50 ` [PATCH 5/5] ASoC: soc-compress: add soc_compr_clean() and call it from soc_compr_open/free() Kuninori Morimoto
2020-11-26 20:05 ` [PATCH 0/5] ASoC: merge soc_compr_open() rollback and soc_compr_free() Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mtze5iwp.wl-kuninori.morimoto.gx@renesas.com \
--to=kuninori.morimoto.gx@renesas.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).