[alsa-devel] [PATCH] ALSA: pcm: fix buffer_bytes max constrained by preallocated bytes issue

Takashi Iwai tiwai at suse.de
Thu Jan 16 08:15:13 CET 2020


On Thu, 16 Jan 2020 05:53:18 +0100,
Keyon Jie wrote:
> 
> With today's code, we preallocate DMA buffer for substreams at pcm_new()
> stage, and the substream->buffer_bytes_max and substream->dma_max will
> save as the actually preallocated buffer size and maximum size that the
> dma buffer can be expanded by at hw_params() state, correspondingly.

No, it's other way round: the former, buffer_bytes_max, is the max
size defined by the driver (i.e. passed in snd_pcm_hardware) and the
latter, dma_max, is the max preallocation size (passed to
preallocation helper).

> At pcm_open() stage, the maximum constraint of HW_PARAM_BUFFER_BYTES is
> set to substream->buffer_bytes_max and returned to user space as the max
> interval of the HW_PARAM_BUFFER_BYTES, this will lead to issue that user
> can't choose any buffer-bytes larger than the preallocated buffer size,
> and the buffer reallocation will never happen actually.
> 
> Here change to use substream->dma_max as the maximum constraint of the
> HW_PARAM_BUFFER_BYTES and fix the issue mentioned above.

I don't think the logic in the current code you're changing is wrong.
If there is any, it must be something else.

This might be rather the FIXME code found in
snd_pcm_hw_constraints_complete()?


thanks,

Takashi

> Signed-off-by: Keyon Jie <yang.jie at linux.intel.com>
> ---
>  sound/core/pcm_native.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
> index c375c41496f8..326e921006e7 100644
> --- a/sound/core/pcm_native.c
> +++ b/sound/core/pcm_native.c
> @@ -2301,7 +2301,7 @@ static int snd_pcm_hw_rule_buffer_bytes_max(struct snd_pcm_hw_params *params,
>  	struct snd_interval t;
>  	struct snd_pcm_substream *substream = rule->private;
>  	t.min = 0;
> -	t.max = substream->buffer_bytes_max;
> +	t.max = substream->dma_max;
>  	t.openmin = 0;
>  	t.openmax = 0;
>  	t.integer = 1;
> -- 
> 2.20.1
> 


More information about the Alsa-devel mailing list