ALSA: pcm: Allow exact buffer preallocation
authorTakashi Iwai <tiwai@suse.de>
Mon, 2 Aug 2021 07:28:03 +0000 (09:28 +0200)
committerTakashi Iwai <tiwai@suse.de>
Wed, 4 Aug 2021 06:08:06 +0000 (08:08 +0200)
commitac9245a5406e6074a1aa211f103629d3f154c5a5
tree068428c901ef2bfeebe94ee8613011e71579f6b7
parent58a95dfa4fdd9c72e62be34dd025d268c1e04a83
ALSA: pcm: Allow exact buffer preallocation

A few drivers want to have rather the exact buffer preallocation at
the driver probe time and keep using it for the whole operations
without allowing dynamic buffer allocation.  For satisfying the
demands, this patch extends the managed buffer allocation API
slightly.

Namely, when 0 is passed to max argument of the allocation helper
functions snd_pcm_set_managed_buffer*(), it treats as if the fixed
size allocation of the given size.  If the pre-allocation fails in
this mode, the function returns now -ENOMEM.  Otherwise, i.e. max
argument is non-zero, the function never returns -ENOMEM but tries to
fall back to the smaller chunks and allows the dynamic allocation
later -- which is still the default behavior until now.

For more intuitive use, also two new helpers are added for handling
the fixed size buffer allocation, too: snd_pcm_set_fixed_buffer() and
snd_pcm_set_fixed_buffer_all().

Acked-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20210802072815.13551-4-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/pcm.h
sound/core/pcm_memory.c