All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: pcm: Fix mmap capability check
@ 2021-07-20  9:26 Takashi Iwai
  2021-07-30  7:19 ` Jaroslav Kysela
  0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2021-07-20  9:26 UTC (permalink / raw)
  To: alsa-devel

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.

Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/core/pcm_native.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index c88c4316c417..6919d2943b9d 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -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,
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: pcm: Fix mmap capability check
  2021-07-20  9:26 [PATCH] ALSA: pcm: Fix mmap capability check Takashi Iwai
@ 2021-07-30  7:19 ` Jaroslav Kysela
  2021-07-30  7:42   ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Jaroslav Kysela @ 2021-07-30  7:19 UTC (permalink / raw)
  To: Takashi Iwai, alsa-devel

On 20. 07. 21 11:26, Takashi Iwai wrote:
> 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?

diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 6a2971a7e6a1..09c0e2a6489c 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -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) {


					Jaroslav


> 
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
>  sound/core/pcm_native.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
> index c88c4316c417..6919d2943b9d 100644
> --- a/sound/core/pcm_native.c
> +++ b/sound/core/pcm_native.c
> @@ -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,
> 


-- 
Jaroslav Kysela <perex@perex.cz>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: pcm: Fix mmap capability check
  2021-07-30  7:19 ` Jaroslav Kysela
@ 2021-07-30  7:42   ` Takashi Iwai
  0 siblings, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2021-07-30  7:42 UTC (permalink / raw)
  To: Jaroslav Kysela; +Cc: alsa-devel

On Fri, 30 Jul 2021 09:19:16 +0200,
Jaroslav Kysela wrote:
> 
> On 20. 07. 21 11:26, Takashi Iwai wrote:
> > 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?
> 
> diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
> index 6a2971a7e6a1..09c0e2a6489c 100644
> --- a/sound/core/pcm_native.c
> +++ b/sound/core/pcm_native.c
> @@ -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) {

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-30  7:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-20  9:26 [PATCH] ALSA: pcm: Fix mmap capability check Takashi Iwai
2021-07-30  7:19 ` Jaroslav Kysela
2021-07-30  7:42   ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.