[alsa-devel] [PATCH v2 3/3] ALSA: pcm: Limit the appl_ptr sync workaround only for old user-space

Takashi Iwai tiwai at suse.de
Wed Jun 21 17:31:14 CEST 2017


Now that user-space (typically alsa-lib) can specify which protocol
version it supports, we can optimize the kernel code depending on the
reported protocol version.

In this patch, we change the previous hack for enforcing the appl_ptr
sync by disabling status/control mmap.  Instead of forcibly disabling,
we disable the status/control mmap selectively only when the
user-space does *not* understand the protocol.  That is, when the
user-space reports it supporting the new protocol version including
the sync appl_ptr feature, we allow the mmap like the normal case.
Then user-space is supposed to do the sync in addition to the mmap.

Signed-off-by: Takashi Iwai <tiwai at suse.de>
---
 sound/core/pcm_native.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 1c53d93e68f2..88c939a86f36 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3394,8 +3394,12 @@ static bool pcm_status_mmap_allowed(struct snd_pcm_file *pcm_file)
 	 * In theory, it should be enough to disallow only PCM control mmap,
 	 * but since the current alsa-lib implementation requires both status
 	 * and control mmaps always paired, we have to disable both of them.
+	 *
+	 * If user_pversion is 2.0.14 or greater, it implies that user-space
+	 * supports the explicit appl_ptr sync, so we still allow the mmap.
 	 */
-	if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR)
+	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;
 }
-- 
2.13.1



More information about the Alsa-devel mailing list