All of lore.kernel.org
 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 v3 03/18] ASoC: soc-pcm: use dai_get_widget() at dpcm_end_walk_at_be()
Date: 17 Feb 2020 11:15:43 +0900	[thread overview]
Message-ID: <877e0maria.wl-kuninori.morimoto.gx@renesas.com> (raw)
In-Reply-To: <87blpyarja.wl-kuninori.morimoto.gx@renesas.com>

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

dpcm_end_walk_at_be() has very duplicate code.

	dpcm_end_walk_at_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>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
---
 sound/soc/soc-pcm.c | 37 ++++++++++++++++---------------------
 1 file changed, 16 insertions(+), 21 deletions(-)

diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index e60dfbcf52b4..62ca275f02b0 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1297,34 +1297,29 @@ static bool dpcm_end_walk_at_be(struct snd_soc_dapm_widget *widget,
 {
 	struct snd_soc_card *card = widget->dapm->card;
 	struct snd_soc_pcm_runtime *rtd;
+	struct snd_soc_dapm_widget *w;
 	struct snd_soc_dai *dai;
+	int stream;
 	int i;
 
-	if (dir == SND_SOC_DAPM_DIR_OUT) {
-		for_each_card_rtds(card, rtd) {
-			if (!rtd->dai_link->no_pcm)
-				continue;
+	/* adjust dir to stream */
+	if (dir == SND_SOC_DAPM_DIR_OUT)
+		stream = SNDRV_PCM_STREAM_PLAYBACK;
+	else
+		stream = SNDRV_PCM_STREAM_CAPTURE;
 
-			if (rtd->cpu_dai->playback_widget == widget)
-				return true;
+	for_each_card_rtds(card, rtd) {
+		if (!rtd->dai_link->no_pcm)
+			continue;
 
-			for_each_rtd_codec_dai(rtd, i, dai) {
-				if (dai->playback_widget == widget)
-					return true;
-			}
-		}
-	} else { /* SND_SOC_DAPM_DIR_IN */
-		for_each_card_rtds(card, rtd) {
-			if (!rtd->dai_link->no_pcm)
-				continue;
+		w = dai_get_widget(rtd->cpu_dai, stream);
+		if (w == widget)
+			return true;
 
-			if (rtd->cpu_dai->capture_widget == widget)
+		for_each_rtd_codec_dai(rtd, i, dai) {
+			w = dai_get_widget(dai, stream);
+			if (w == widget)
 				return true;
-
-			for_each_rtd_codec_dai(rtd, i, dai) {
-				if (dai->capture_widget == widget)
-					return true;
-			}
 		}
 	}
 
-- 
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-17  2:18 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-17  2:15 [alsa-devel] [PATCH v3 00/18] ASoC: soc-pcm cleanup step3 Kuninori Morimoto
2020-02-17  2:15 ` [alsa-devel] [PATCH v3 01/18] ASoC: soc-pcm: move dai_get_widget() Kuninori Morimoto
2020-02-17  2:15 ` [alsa-devel] [PATCH v3 02/18] ASoC: soc-pcm: use dai_get_widget() at dpcm_get_be() Kuninori Morimoto
2020-02-17  2:15 ` Kuninori Morimoto [this message]
2020-02-17  2:15 ` [alsa-devel] [PATCH v3 04/18] ASoC: soc-pcm: use dpcm_get_be() at dpcm_end_walk_at_be() Kuninori Morimoto
2020-02-17  2:15 ` [alsa-devel] [PATCH v3 05/18] ASoC: soc-pcm: remove soc_dpcm_be_digital_mute() Kuninori Morimoto
2020-02-17  2:16 ` [alsa-devel] [PATCH v3 06/18] ASoC: soc-pcm: remove snd_soc_dpcm_be_get/set_state() Kuninori Morimoto
2020-02-17  2:16 ` [alsa-devel] [PATCH v3 07/18] ASoC: soc-pcm: add snd_soc_dpcm_can_be() and remove duplicate code Kuninori Morimoto
2020-02-17  2:16 ` [alsa-devel] [PATCH v3 08/18] ASoC: soc-pcm: use goto and remove multi return Kuninori Morimoto
2020-02-17  2:16 ` [alsa-devel] [PATCH v3 09/18] ASoC: soc-pcm: merge playback/cature_active into stream_active Kuninori Morimoto
2020-02-17  2:16 ` [alsa-devel] [PATCH v3 10/18] ASoC: soc.h: add for_each_pcm_streams() Kuninori Morimoto
2020-02-17  7:55   ` Takashi Iwai
2020-02-17  8:24     ` Kuninori Morimoto
2020-02-17  2:16 ` [alsa-devel] [PATCH v3 11/18] ASoC: soc-core: use for_each_pcm_streams() macro Kuninori Morimoto
2020-02-17  2:16 ` [alsa-devel] [PATCH v3 12/18] ASoC: soc-pcm: " Kuninori Morimoto
2020-02-17  2:16 ` [alsa-devel] [PATCH v3 13/18] ASoC: soc-generic-dmaengine-pcm: " Kuninori Morimoto
2020-02-17  2:16 ` [alsa-devel] [PATCH v3 14/18] ASoC: dwc: dwc-i2s: " Kuninori Morimoto
2020-02-17  2:16 ` [alsa-devel] [PATCH v3 15/18] ASoC: fsl: fsl_asrc_dma: " Kuninori Morimoto
2020-02-17  2:16 ` [alsa-devel] [PATCH v3 16/18] ASoC: qcom: lpass-platform: " Kuninori Morimoto
2020-02-17  2:16 ` [alsa-devel] [PATCH v3 17/18] ASoC: sof: sof-audio: " Kuninori Morimoto
2020-02-17  2:16 ` [alsa-devel] [PATCH v3 18/18] ALSA: usx2y: " Kuninori Morimoto
2020-02-17  7:55   ` Takashi Iwai

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=877e0maria.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.