diff mbox series

[13/25] ASoC: soc-component: add snd_soc_component_mmap()

Message ID 87k1c8td67.wl-kuninori.morimoto.gx@renesas.com (mailing list archive)
State New, archived
Headers show
Series ASoC: add soc-component.c | expand

Commit Message

Kuninori Morimoto July 24, 2019, 1:52 a.m. UTC
From: Kuninori Morimoto <kuninori.morimoto.gx@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_mmap() and use it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 include/sound/soc-component.h |  3 +++
 sound/soc/soc-component.c     | 11 +++++++++++
 sound/soc/soc-pcm.c           |  9 ++++-----
 3 files changed, 18 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h
index f3314d0..223b0ce 100644
--- a/include/sound/soc-component.h
+++ b/include/sound/soc-component.h
@@ -349,5 +349,8 @@  int snd_soc_component_copy_user(struct snd_soc_component *component,
 struct page *snd_soc_component_page(struct snd_soc_component *component,
 				    struct snd_pcm_substream *substream,
 				    unsigned long offset);
+int snd_soc_component_mmap(struct snd_soc_component *component,
+			   struct snd_pcm_substream *substream,
+			   struct vm_area_struct *vma);
 
 #endif /* __SOC_COMPONENT_H */
diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c
index dcf27c8..166a8c8 100644
--- a/sound/soc/soc-component.c
+++ b/sound/soc/soc-component.c
@@ -392,3 +392,14 @@  struct page *snd_soc_component_page(struct snd_soc_component *component,
 
 	return ERR_PTR(-ENOTSUPP);
 }
+
+int snd_soc_component_mmap(struct snd_soc_component *component,
+			   struct snd_pcm_substream *substream,
+			   struct vm_area_struct *vma)
+{
+	if (component->driver->ops &&
+	    component->driver->ops->mmap)
+		return component->driver->ops->mmap(substream, vma);
+
+	return -ENOTSUPP;
+}
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index bbc9471..c483db0 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -2947,16 +2947,15 @@  static int soc_rtdcom_mmap(struct snd_pcm_substream *substream,
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
 	struct snd_soc_rtdcom_list *rtdcom;
 	struct snd_soc_component *component;
+	int ret;
 
 	for_each_rtdcom(rtd, rtdcom) {
 		component = rtdcom->component;
 
-		if (!component->driver->ops ||
-		    !component->driver->ops->mmap)
-			continue;
-
+		ret = snd_soc_component_mmap(component, substream, vma);
 		/* FIXME. it returns 1st mmap now */
-		return component->driver->ops->mmap(substream, vma);
+		if (ret != -ENOTSUPP)
+			return ret;
 	}
 
 	return -EINVAL;