ALSA: pcm: Fix mmap capability check
PATCH 1/1 ALSA: pcm: Fix mmap capability check
The hw_support_mmap() doesn't cover all memory allocation types and might use a wrong device pointer for checking the capability. Check the all memory allocation types more completely.
--- sound/core/pcm_native.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
sound/core/pcm_native.c +10 -4
@@ -246,12 +246,18 @@ static bool hw_support_mmap(struct snd_pcm_substream *substream)if (!(substream->runtime->hw.info &SNDRV_PCM_INFO_MMAP ))return false; -if (substream->ops->mmap || - (substream->dma_buffer.dev.type !=SNDRV_DMA_TYPE_DEV && - substream->dma_buffer.dev.type !=SNDRV_DMA_TYPE_DEV_UC )) +if (substream->ops->mmap)return true; -return dma_can_mmap (substream->dma_buffer.dev.dev); +switch (substream->dma_buffer.dev.type) { +case SNDRV_DMA_TYPE_UNKNOWN : +return false; +case SNDRV_DMA_TYPE_CONTINUOUS : +case SNDRV_DMA_TYPE_VMALLOC : +return true; +default : +return dma_can_mmap (substream->dma_buffer.dev.dev); + } } static int constrain_mask_params(struct snd_pcm_substream *substream,
Signature · 1 line
2.26.2
Jaroslav Kysela
maintainerQuoted 3 lines · Takashi Iwai
The
hw_support_mmap()doesn't cover all memory allocation types and might use a wrong device pointer for checking the capability. Check the all memory allocation types more completely.
This change breaks mmap for the snd-dummy driver (fake_buffer). It seems that we need this fix?
sound/core/pcm_native.c +0 -0
@@ -246,7 +246,7 @@ static bool hw_support_mmap(struct snd_pcm_substream
*substream)
if (!(substream->runtime->hw.info & SNDRV_PCM_INFO_MMAP))
return false;- if (substream->ops->mmap)
+ if (substream->ops->mmap || substream->ops->page)
return true;
switch (substream->dma_buffer.dev.type) {
JaroslavQuoted 35 lines
Cc <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- sound/core/pcm_native.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)sound/core/pcm_native.c +10
-4@@ -246,12 +246,18 @@ static bool hw_support_mmap(struct snd_pcm_substream *substream)if (!(substream->runtime->hw.info &SNDRV_PCM_INFO_MMAP ))return false; -if (substream->ops->mmap || - (substream->dma_buffer.dev.type !=SNDRV_DMA_TYPE_DEV && - substream->dma_buffer.dev.type !=SNDRV_DMA_TYPE_DEV_UC )) +if (substream->ops->mmap)return true; -return dma_can_mmap (substream->dma_buffer.dev.dev); +switch (substream->dma_buffer.dev.type) { +case SNDRV_DMA_TYPE_UNKNOWN : +return false; +case SNDRV_DMA_TYPE_CONTINUOUS : +case SNDRV_DMA_TYPE_VMALLOC : +return true; +default : +return dma_can_mmap (substream->dma_buffer.dev.dev); + } } static int constrain_mask_params(struct snd_pcm_substream *substream,
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
Quoted 22 lines · Jaroslav Kysela
Quoted 3 lines · Takashi Iwai
The
hw_support_mmap()doesn't cover all memory allocation types and might use a wrong device pointer for checking the capability. Check the all memory allocation types more completely.This change breaks mmap for the snd-dummy driver (
fake_buffer). It seems that we need this fix?sound/core/pcm_native.c +1
-1@@ -246,7 +246,7 @@ static bool hw_support_mmap(struct snd_pcm_substream *substream)if (!(substream->runtime->hw.info &SNDRV_PCM_INFO_MMAP ))return false; -if (substream->ops->mmap) +if (substream->ops->mmap || substream->ops->page)return true;
Quoted 1 line
switch (substream->dma_buffer.dev.type) {Yes, that would work. Or allowing the mmap for unknown buffer type by blindly relying to the hw.info flag. But ops->page check looks safer.
Care to submit a proper patch? Thanks!
Takashi