[alsa-devel] [PATCH 12/25] ASoC: soc-component: add snd_soc_component_page()

Kuninori Morimoto kuninori.morimoto.gx at renesas.com
Wed Jul 24 03:52:15 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_page() and use it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
 include/sound/soc-component.h |  3 +++
 sound/soc/soc-component.c     | 11 +++++++++++
 sound/soc/soc-pcm.c           |  8 ++------
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h
index b86aecf..f3314d0 100644
--- a/include/sound/soc-component.h
+++ b/include/sound/soc-component.h
@@ -346,5 +346,8 @@ int snd_soc_component_copy_user(struct snd_soc_component *component,
 				struct snd_pcm_substream *substream,
 				int channel, unsigned long pos,
 				void __user *buf, unsigned long bytes);
+struct page *snd_soc_component_page(struct snd_soc_component *component,
+				    struct snd_pcm_substream *substream,
+				    unsigned long offset);
 
 #endif /* __SOC_COMPONENT_H */
diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c
index 881450d2..dcf27c8 100644
--- a/sound/soc/soc-component.c
+++ b/sound/soc/soc-component.c
@@ -381,3 +381,14 @@ int snd_soc_component_copy_user(struct snd_soc_component *component,
 
 	return -ENOTSUPP;
 }
+
+struct page *snd_soc_component_page(struct snd_soc_component *component,
+				    struct snd_pcm_substream *substream,
+				    unsigned long offset)
+{
+	if (component->driver->ops &&
+	    component->driver->ops->page)
+		return component->driver->ops->page(substream, offset);
+
+	return ERR_PTR(-ENOTSUPP);
+}
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index f1d3404..bbc9471 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -2932,13 +2932,9 @@ static struct page *soc_rtdcom_page(struct snd_pcm_substream *substream,
 	for_each_rtdcom(rtd, rtdcom) {
 		component = rtdcom->component;
 
-		if (!component->driver->ops ||
-		    !component->driver->ops->page)
-			continue;
-
 		/* FIXME. it returns 1st page now */
-		page = component->driver->ops->page(substream, offset);
-		if (page)
+		page = snd_soc_component_page(component, substream, offset);
+		if (page != ERR_PTR(-ENOTSUPP))
 			return page;
 	}
 
-- 
2.7.4



More information about the Alsa-devel mailing list