alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
To: Mark Brown <broonie@kernel.org>
Cc: Linux-ALSA <alsa-devel@alsa-project.org>
Subject: [alsa-devel] [PATCH 02/10] ASoC: soc-pcm: use dai_get_widget() at dpcm_get_be()
Date: 13 Feb 2020 13:26:13 +0900	[thread overview]
Message-ID: <878sl7ru3n.wl-kuninori.morimoto.gx@renesas.com> (raw)
In-Reply-To: <87blq3ru4w.wl-kuninori.morimoto.gx@renesas.com>


From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

dpcm_get_be() has very duplicate code.

	dpcm_get_be()
	{
		...
		if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
(1)			/* code for Playback */
		} else  {
(2)			/* code for Capture */
		}
	}

The difference between Playback (1) and Capture (2) code is pointer only
(= "playback_widget" or "caputre_widget").
OTOH, now we already has dai_get_widget() for it.
This means we can merge (1) and (2).
This patch do it and remove duplicated code.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/soc-pcm.c | 41 ++++++++++++-----------------------------
 1 file changed, 12 insertions(+), 29 deletions(-)

diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index a8adc8d06c05..e60dfbcf52b4 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1246,47 +1246,30 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
 		struct snd_soc_dapm_widget *widget, int stream)
 {
 	struct snd_soc_pcm_runtime *be;
+	struct snd_soc_dapm_widget *w;
 	struct snd_soc_dai *dai;
 	int i;
 
 	dev_dbg(card->dev, "ASoC: find BE for widget %s\n", widget->name);
 
-	if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
-		for_each_card_rtds(card, be) {
+	for_each_card_rtds(card, be) {
 
-			if (!be->dai_link->no_pcm)
-				continue;
+		if (!be->dai_link->no_pcm)
+			continue;
 
-			dev_dbg(card->dev, "ASoC: try BE : %s\n",
-				be->cpu_dai->playback_widget ?
-				be->cpu_dai->playback_widget->name : "(not set)");
+		w = dai_get_widget(be->cpu_dai, stream);
 
-			if (be->cpu_dai->playback_widget == widget)
-				return be;
+		dev_dbg(card->dev, "ASoC: try BE : %s\n",
+			w ? w->name : "(not set)");
 
-			for_each_rtd_codec_dai(be, i, dai) {
-				if (dai->playback_widget == widget)
-					return be;
-			}
-		}
-	} else {
-
-		for_each_card_rtds(card, be) {
-
-			if (!be->dai_link->no_pcm)
-				continue;
+		if (w == widget)
+			return be;
 
-			dev_dbg(card->dev, "ASoC: try BE %s\n",
-				be->cpu_dai->capture_widget ?
-				be->cpu_dai->capture_widget->name : "(not set)");
+		for_each_rtd_codec_dai(be, i, dai) {
+			w = dai_get_widget(dai, stream);
 
-			if (be->cpu_dai->capture_widget == widget)
+			if (w == widget)
 				return be;
-
-			for_each_rtd_codec_dai(be, i, dai) {
-				if (dai->capture_widget == widget)
-					return be;
-			}
 		}
 	}
 
-- 
2.17.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  parent reply	other threads:[~2020-02-13  4:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-13  4:25 [alsa-devel] [PATCH 00/10] ASoC: soc-pcm cleanup step3 Kuninori Morimoto
2020-02-13  4:26 ` [alsa-devel] [PATCH 01/10] ASoC: soc-pcm: move dai_get_widget() Kuninori Morimoto
2020-02-13  4:26 ` Kuninori Morimoto [this message]
2020-02-13  4:26 ` [alsa-devel] [PATCH 03/10] ASoC: soc-pcm: use dai_get_widget() at dpcm_end_walk_at_be() Kuninori Morimoto
2020-02-13  4:26 ` [alsa-devel] [PATCH 04/10] ASoC: soc-pcm: use dpcm_get_be() " Kuninori Morimoto
2020-02-13  4:26 ` [alsa-devel] [PATCH 05/10] ASoC: soc-pcm: remove soc_dpcm_be_digital_mute() Kuninori Morimoto
2020-02-13  4:26 ` [alsa-devel] [PATCH 06/10] ASoC: soc-pcm: remove snd_soc_dpcm_be_get/set_state() Kuninori Morimoto
2020-02-13  4:26 ` [alsa-devel] [PATCH 07/10] ASoC: soc-pcm: add snd_soc_dpcm_can_be() and remove duplicate code Kuninori Morimoto
2020-02-13 15:56   ` Pierre-Louis Bossart
2020-02-14  0:04     ` Kuninori Morimoto
2020-02-13 17:15   ` Ranjani Sridharan
2020-02-14  0:08     ` Kuninori Morimoto
2020-02-13  4:26 ` [alsa-devel] [PATCH 08/10] ASoC: soc-pcm: use goto and remove multi return Kuninori Morimoto
2020-02-13  4:26 ` [alsa-devel] [PATCH 09/10] ASoC: soc-pcm: care Multi Codec at soc_dpcm_fe_runtime_update() Kuninori Morimoto
2020-02-13 16:10   ` Pierre-Louis Bossart
2020-02-14  0:07     ` Kuninori Morimoto
2020-02-13  4:26 ` [alsa-devel] [PATCH 10/10] ASoC: soc.h: add for_each_pcm_stream() Kuninori Morimoto
2020-02-13  6:35   ` Takashi Iwai
2020-02-13  6:46     ` Kuninori Morimoto
2020-02-13 16:14   ` Pierre-Louis Bossart
2020-02-14  0:05     ` Kuninori Morimoto

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=878sl7ru3n.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).