[alsa-devel] [PATCH 14/25] ASoC: soc-component: add snd_soc_component_pcm_new()

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


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

Current ALSA SoC is directly using component->driver->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_pcm() 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     | 9 +++++++++
 sound/soc/soc-pcm.c           | 5 +----
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h
index 223b0ce..9e61a52 100644
--- a/include/sound/soc-component.h
+++ b/include/sound/soc-component.h
@@ -352,5 +352,7 @@ struct page *snd_soc_component_page(struct snd_soc_component *component,
 int snd_soc_component_mmap(struct snd_soc_component *component,
 			   struct snd_pcm_substream *substream,
 			   struct vm_area_struct *vma);
+int snd_soc_component_pcm_new(struct snd_soc_component *component,
+			      struct snd_soc_pcm_runtime *rtd);
 
 #endif /* __SOC_COMPONENT_H */
diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c
index 166a8c8..8f3679e 100644
--- a/sound/soc/soc-component.c
+++ b/sound/soc/soc-component.c
@@ -403,3 +403,12 @@ int snd_soc_component_mmap(struct snd_soc_component *component,
 
 	return -ENOTSUPP;
 }
+
+int snd_soc_component_pcm_new(struct snd_soc_component *component,
+			      struct snd_soc_pcm_runtime *rtd)
+{
+	if (component->driver->pcm_new)
+		return component->driver->pcm_new(rtd);
+
+	return 0;
+}
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index c483db0..466802f 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -3089,10 +3089,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 	for_each_rtdcom(rtd, rtdcom) {
 		component = rtdcom->component;
 
-		if (!component->driver->pcm_new)
-			continue;
-
-		ret = component->driver->pcm_new(rtd);
+		ret = snd_soc_component_pcm_new(component, rtd);
 		if (ret < 0) {
 			dev_err(component->dev,
 				"ASoC: pcm constructor failed: %d\n",
-- 
2.7.4



More information about the Alsa-devel mailing list