From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: broonie@kernel.org
Cc: vinod.koul@intel.com, patches@opensource.cirrus.com,
alsa-devel@alsa-project.org, lgirdwood@gmail.com,
kuninori.morimoto.gx@renesas.com
Subject: [PATCH 3/3] ASoC: compress: Add helper functions for component open/free
Date: Tue, 24 Apr 2018 16:39:03 +0100 [thread overview]
Message-ID: <20180424153903.7693-3-ckeepax@opensource.cirrus.com> (raw)
In-Reply-To: <20180424153903.7693-1-ckeepax@opensource.cirrus.com>
There are 2 loops calling open and 4 loops calling free for all the
components on a DAI link. Factor out these loops into helper functions
to make the code a little clearer.
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
I am looking at refactoring some of the other callbacks as well, but
there is quite a lot to think about. So thought I would get these out
for people to look at whilst I work out what makes sense for the rest.
Thanks,
Charles
sound/soc/soc-compress.c | 141 +++++++++++++++++++++--------------------------
1 file changed, 62 insertions(+), 79 deletions(-)
diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
index abc00c6cc2d7..ba56f87f96d4 100644
--- a/sound/soc/soc-compress.c
+++ b/sound/soc/soc-compress.c
@@ -26,26 +26,14 @@
#include <sound/initval.h>
#include <sound/soc-dpcm.h>
-static int soc_compr_open(struct snd_compr_stream *cstream)
+static int soc_compr_components_open(struct snd_compr_stream *cstream,
+ struct snd_soc_component **last)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_component *component;
struct snd_soc_rtdcom_list *rtdcom;
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
int ret;
- mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
-
- if (cpu_dai->driver->cops && cpu_dai->driver->cops->startup) {
- ret = cpu_dai->driver->cops->startup(cstream, cpu_dai);
- if (ret < 0) {
- dev_err(cpu_dai->dev,
- "Compress ASoC: can't open interface %s: %d\n",
- cpu_dai->name, ret);
- goto out;
- }
- }
-
for_each_rtdcom(rtd, rtdcom) {
component = rtdcom->component;
@@ -58,10 +46,61 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
dev_err(component->dev,
"Compress ASoC: can't open platform %s: %d\n",
component->name, ret);
- goto machine_err;
+
+ *last = component;
+ return ret;
+ }
+ }
+
+ *last = NULL;
+ return 0;
+}
+
+static int soc_compr_components_free(struct snd_compr_stream *cstream,
+ struct snd_soc_component *last)
+{
+ struct snd_soc_pcm_runtime *rtd = cstream->private_data;
+ struct snd_soc_component *component;
+ struct snd_soc_rtdcom_list *rtdcom;
+
+ for_each_rtdcom(rtd, rtdcom) {
+ component = rtdcom->component;
+
+ if (component == last)
+ break;
+
+ if (!component->driver->compr_ops ||
+ !component->driver->compr_ops->free)
+ continue;
+
+ component->driver->compr_ops->free(cstream);
+ }
+
+ return 0;
+}
+
+static int soc_compr_open(struct snd_compr_stream *cstream)
+{
+ struct snd_soc_pcm_runtime *rtd = cstream->private_data;
+ struct snd_soc_component *component;
+ struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+ int ret;
+
+ mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
+
+ if (cpu_dai->driver->cops && cpu_dai->driver->cops->startup) {
+ ret = cpu_dai->driver->cops->startup(cstream, cpu_dai);
+ if (ret < 0) {
+ dev_err(cpu_dai->dev,
+ "Compress ASoC: can't open interface %s: %d\n",
+ cpu_dai->name, ret);
+ goto out;
}
}
- component = NULL;
+
+ ret = soc_compr_components_open(cstream, &component);
+ if (ret < 0)
+ goto machine_err;
if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->startup) {
ret = rtd->dai_link->compr_ops->startup(cstream);
@@ -80,18 +119,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
return 0;
machine_err:
- for_each_rtdcom(rtd, rtdcom) {
- struct snd_soc_component *err_comp = rtdcom->component;
-
- if (err_comp == component)
- break;
-
- if (!err_comp->driver->compr_ops ||
- !err_comp->driver->compr_ops->free)
- continue;
-
- err_comp->driver->compr_ops->free(cstream);
- }
+ soc_compr_components_free(cstream, component);
if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
cpu_dai->driver->cops->shutdown(cstream, cpu_dai);
@@ -106,7 +134,6 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
struct snd_pcm_substream *fe_substream =
fe->pcm->streams[cstream->direction].substream;
struct snd_soc_component *component;
- struct snd_soc_rtdcom_list *rtdcom;
struct snd_soc_dai *cpu_dai = fe->cpu_dai;
struct snd_soc_dpcm *dpcm;
struct snd_soc_dapm_widget_list *list;
@@ -130,22 +157,9 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
}
}
- for_each_rtdcom(fe, rtdcom) {
- component = rtdcom->component;
-
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->open)
- continue;
-
- ret = component->driver->compr_ops->open(cstream);
- if (ret < 0) {
- dev_err(component->dev,
- "Compress ASoC: can't open platform %s: %d\n",
- component->name, ret);
- goto machine_err;
- }
- }
- component = NULL;
+ ret = soc_compr_components_open(cstream, &component);
+ if (ret < 0)
+ goto machine_err;
if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->startup) {
ret = fe->dai_link->compr_ops->startup(cstream);
@@ -199,18 +213,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown)
fe->dai_link->compr_ops->shutdown(cstream);
machine_err:
- for_each_rtdcom(fe, rtdcom) {
- struct snd_soc_component *err_comp = rtdcom->component;
-
- if (err_comp == component)
- break;
-
- if (!err_comp->driver->compr_ops ||
- !err_comp->driver->compr_ops->free)
- continue;
-
- err_comp->driver->compr_ops->free(cstream);
- }
+ soc_compr_components_free(cstream, component);
if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
cpu_dai->driver->cops->shutdown(cstream, cpu_dai);
@@ -252,8 +255,6 @@ static void close_delayed_work(struct work_struct *work)
static int soc_compr_free(struct snd_compr_stream *cstream)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
- struct snd_soc_component *component;
- struct snd_soc_rtdcom_list *rtdcom;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai;
int stream;
@@ -278,15 +279,7 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->shutdown)
rtd->dai_link->compr_ops->shutdown(cstream);
- for_each_rtdcom(rtd, rtdcom) {
- component = rtdcom->component;
-
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->free)
- continue;
-
- component->driver->compr_ops->free(cstream);
- }
+ soc_compr_components_free(cstream, NULL);
if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
cpu_dai->driver->cops->shutdown(cstream, cpu_dai);
@@ -316,8 +309,6 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
static int soc_compr_free_fe(struct snd_compr_stream *cstream)
{
struct snd_soc_pcm_runtime *fe = cstream->private_data;
- struct snd_soc_component *component;
- struct snd_soc_rtdcom_list *rtdcom;
struct snd_soc_dai *cpu_dai = fe->cpu_dai;
struct snd_soc_dpcm *dpcm;
int stream, ret;
@@ -355,15 +346,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown)
fe->dai_link->compr_ops->shutdown(cstream);
- for_each_rtdcom(fe, rtdcom) {
- component = rtdcom->component;
-
- if (!component->driver->compr_ops ||
- !component->driver->compr_ops->free)
- continue;
-
- component->driver->compr_ops->free(cstream);
- }
+ soc_compr_components_free(cstream, NULL);
if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
cpu_dai->driver->cops->shutdown(cstream, cpu_dai);
--
2.11.0
next prev parent reply other threads:[~2018-04-24 15:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-24 15:39 [PATCH 1/3] ASoC: compress: Only call free for components which have been opened Charles Keepax
2018-04-24 15:39 ` [PATCH 2/3] ASoC: Remove platform code now everything is componentised Charles Keepax
2018-04-25 8:53 ` Vinod Koul
2018-04-24 15:39 ` Charles Keepax [this message]
2018-04-25 9:07 ` [PATCH 3/3] ASoC: compress: Add helper functions for component open/free Vinod Koul
2018-04-26 11:46 ` Applied "ASoC: compress: Add helper functions for component open/free" to the asoc tree Mark Brown
2018-04-26 11:49 ` Mark Brown
2018-04-26 11:53 ` Mark Brown
2018-04-25 8:52 ` [PATCH 1/3] ASoC: compress: Only call free for components which have been opened Vinod Koul
2018-04-26 11:46 ` Applied "ASoC: compress: Only call free for components which have been opened" to the asoc tree Mark Brown
2018-04-26 11:49 ` Mark Brown
2018-04-26 11:53 ` 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=20180424153903.7693-3-ckeepax@opensource.cirrus.com \
--to=ckeepax@opensource.cirrus.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=kuninori.morimoto.gx@renesas.com \
--cc=lgirdwood@gmail.com \
--cc=patches@opensource.cirrus.com \
--cc=vinod.koul@intel.com \
/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).