[alsa-devel] [PATCH 04/25] ASoC: soc-component: add snd_soc_component_close()

Kuninori Morimoto kuninori.morimoto.gx at renesas.com
Wed Jul 24 03:51:35 CEST 2019


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

Current ALSA SoC is directly using component->driver->ops->xxx,
thus, it is deep nested, and makes code difficult to read,
and is not good for encapsulation.
This patch adds new snd_soc_component_close() and use it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
 include/sound/soc-component.h |  2 ++
 sound/soc/soc-component.c     | 10 ++++++++++
 sound/soc/soc-pcm.c           |  5 +----
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h
index 306c9cf..6357c0a 100644
--- a/include/sound/soc-component.h
+++ b/include/sound/soc-component.h
@@ -325,5 +325,7 @@ int snd_soc_component_force_enable_pin_unlocked(
 /* component driver ops */
 int snd_soc_component_open(struct snd_soc_component *component,
 			   struct snd_pcm_substream *substream);
+int snd_soc_component_close(struct snd_soc_component *component,
+			    struct snd_pcm_substream *substream);
 
 #endif /* __SOC_COMPONENT_H */
diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c
index 3e9172e..d9191df 100644
--- a/sound/soc/soc-component.c
+++ b/sound/soc/soc-component.c
@@ -295,3 +295,13 @@ int snd_soc_component_open(struct snd_soc_component *component,
 
 	return 0;
 }
+
+int snd_soc_component_close(struct snd_soc_component *component,
+			    struct snd_pcm_substream *substream)
+{
+	if (component->driver->ops &&
+	    component->driver->ops->close)
+		return component->driver->ops->close(substream);
+
+	return 0;
+}
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index c98b4da..86d2e6b 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -472,10 +472,7 @@ static int soc_pcm_components_close(struct snd_pcm_substream *substream,
 		if (component == last)
 			break;
 
-		if (component->driver->ops &&
-		    component->driver->ops->close)
-			component->driver->ops->close(substream);
-
+		snd_soc_component_close(component, substream);
 		snd_soc_component_module_put(component, 1);
 	}
 
-- 
2.7.4



More information about the Alsa-devel mailing list