From: Jaroslav Kysela <perex@perex.cz>
To: ALSA development <alsa-devel@alsa-project.org>
Cc: Baolin Wang <baolin.wang@linaro.org>,
Takashi Iwai <tiwai@suse.de>, Phil Burk <philburk@google.com>,
Zach Riggle <riggle@google.com>, Mark Brown <broonie@kernel.org>,
Leo Yan <leo.yan@linaro.org>
Subject: [PATCH v6 2/3] ALSA: pcm: merge pcm_..._mmap_allowed fcns to the snd_pcm_mmap_... fcns
Date: Mon, 4 Feb 2019 19:38:16 +0100 [thread overview]
Message-ID: <20190204183817.975-3-perex@perex.cz> (raw)
In-Reply-To: <20190204183817.975-1-perex@perex.cz>
There is no benefit to have this code separate. The result code is even
smaller and simplier for the review. No functional change.
diffstat: 23 insertions(+), 34 deletions(-)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
sound/core/pcm_native.c | 56 +++++++++++++++++++------------------------------
1 file changed, 22 insertions(+), 34 deletions(-)
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 06385bd5d20d..0f3887980d9b 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3297,6 +3297,16 @@ static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file
struct vm_area_struct *area)
{
long size;
+ struct snd_pcm_file *pcm_file = file->private_data;
+ if (pcm_file->no_compat_mmap)
+ return -ENXIO;
+ /* See snd_pcm_mmap_control() below.
+ * Since older alsa-lib requires both status and control mmaps to be
+ * coupled, we have to disable the status mmap for old alsa-lib, too.
+ */
+ if (pcm_file->user_pversion < SNDRV_PROTOCOL_VERSION(2, 0, 14) &&
+ (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR))
+ return -ENXIO;
if (!(area->vm_flags & VM_READ))
return -EINVAL;
size = area->vm_end - area->vm_start;
@@ -3333,6 +3343,15 @@ static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file
struct vm_area_struct *area)
{
long size;
+ struct snd_pcm_file *pcm_file = file->private_data;
+ if (pcm_file->no_compat_mmap)
+ return -ENXIO;
+ /* Disallow the control mmap when SYNC_APPLPTR flag is set;
+ * it enforces the user-space to fall back to snd_pcm_sync_ptr(),
+ * thus it effectively assures the manual update of appl_ptr.
+ */
+ if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR)
+ return -ENXIO;
if (!(area->vm_flags & VM_READ))
return -EINVAL;
size = area->vm_end - area->vm_start;
@@ -3344,50 +3363,23 @@ static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file
return 0;
}
-static bool pcm_status_mmap_allowed(struct snd_pcm_file *pcm_file)
-{
- if (pcm_file->no_compat_mmap)
- return false;
- /* See pcm_control_mmap_allowed() below.
- * Since older alsa-lib requires both status and control mmaps to be
- * coupled, we have to disable the status mmap for old alsa-lib, too.
- */
- if (pcm_file->user_pversion < SNDRV_PROTOCOL_VERSION(2, 0, 14) &&
- (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR))
- return false;
- return true;
-}
-
-static bool pcm_control_mmap_allowed(struct snd_pcm_file *pcm_file)
-{
- if (pcm_file->no_compat_mmap)
- return false;
- /* Disallow the control mmap when SYNC_APPLPTR flag is set;
- * it enforces the user-space to fall back to snd_pcm_sync_ptr(),
- * thus it effectively assures the manual update of appl_ptr.
- */
- if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR)
- return false;
- return true;
-}
-
#else /* ! coherent mmap */
+
/*
* don't support mmap for status and control records.
*/
-#define pcm_status_mmap_allowed(pcm_file) false
-#define pcm_control_mmap_allowed(pcm_file) false
-
static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file *file,
struct vm_area_struct *area)
{
return -ENXIO;
}
+
static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file *file,
struct vm_area_struct *area)
{
return -ENXIO;
}
+
#endif /* coherent mmap */
static inline struct page *
@@ -3561,12 +3553,8 @@ static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area)
offset = area->vm_pgoff << PAGE_SHIFT;
switch (offset) {
case SNDRV_PCM_MMAP_OFFSET_STATUS:
- if (!pcm_status_mmap_allowed(pcm_file))
- return -ENXIO;
return snd_pcm_mmap_status(substream, file, area);
case SNDRV_PCM_MMAP_OFFSET_CONTROL:
- if (!pcm_control_mmap_allowed(pcm_file))
- return -ENXIO;
return snd_pcm_mmap_control(substream, file, area);
default:
return snd_pcm_mmap_data(substream, file, area);
--
2.13.6
next prev parent reply other threads:[~2019-02-04 18:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-04 18:38 [PATCH v6 0/3] ALSA: pcm: anonymous dup implementation Jaroslav Kysela
2019-02-04 18:38 ` [PATCH v6 1/3] ALSA: pcm: implement the anonymous dup (inode file descriptor) Jaroslav Kysela
2019-02-04 18:38 ` Jaroslav Kysela [this message]
2019-02-04 18:38 ` [PATCH v6 3/3] ALSA: pcm: implement the mmap buffer mode for the anonymous dup Jaroslav Kysela
2019-02-07 16:29 ` [PATCH v6 0/3] ALSA: pcm: anonymous dup implementation Mark Brown
2019-02-08 16:14 ` Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190204183817.975-3-perex@perex.cz \
--to=perex@perex.cz \
--cc=alsa-devel@alsa-project.org \
--cc=baolin.wang@linaro.org \
--cc=broonie@kernel.org \
--cc=leo.yan@linaro.org \
--cc=philburk@google.com \
--cc=riggle@google.com \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox