[PATCH v3 03/18] ASoC: soc-pcm: use dai_get_widget() at dpcm_end_walk_at_be()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Kuninori Morimoto <kuninori.morimoto.gx@xxxxxxxxxxx>

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@xxxxxxxxxxx>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@xxxxxxxxxxxxxxx>
---
 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@xxxxxxxxxxxxxxxx
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel



[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux