ALSA: memalloc: Allow NULL device for SNDRV_DMA_TYPE_CONTINUOUS type

Currently we pass the artificial device pointer to the allocation
helper in the case of SNDRV_DMA_TYPE_CONTINUOUS for passing the GFP
flags.  But all common cases are the allocations with GFP_KERNEL, and
it's messy to put this in each place.

In this patch, the memalloc core helper is changed to accept the NULL
device pointer and it treats as the default mode, GFP_KERNEL, so that
all callers can omit the complex argument but just leave NULL.

Link: https://lore.kernel.org/r/20191105080138.1260-2-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2019-11-05 09:01:35 +01:00
Родитель 42ec336f1f
Коммит 08422d2c55
2 изменённых файлов: 16 добавлений и 9 удалений

Просмотреть файл

@ -3523,12 +3523,14 @@ The second argument (type) and the third argument (device pointer) are
dependent on the bus. For normal devices, pass the device pointer dependent on the bus. For normal devices, pass the device pointer
(typically identical as ``card->dev``) to the third argument with (typically identical as ``card->dev``) to the third argument with
``SNDRV_DMA_TYPE_DEV`` type. For the continuous buffer unrelated to the ``SNDRV_DMA_TYPE_DEV`` type. For the continuous buffer unrelated to the
bus can be pre-allocated with ``SNDRV_DMA_TYPE_CONTINUOUS`` type and the bus can be pre-allocated with ``SNDRV_DMA_TYPE_CONTINUOUS`` type.
``snd_dma_continuous_data(GFP_KERNEL)`` device pointer, where You can pass NULL to the device pointer in that case, which is the
``GFP_KERNEL`` is the kernel allocation flag to use. For the default mode implying to allocate with ``GFP_KRENEL`` flag.
scatter-gather buffers, use ``SNDRV_DMA_TYPE_DEV_SG`` with the device If you need a different GFP flag, you can pass it by encoding the flag
pointer (see the `Non-Contiguous Buffers`_ into the device pointer via a special macro
section). :c:func:`snd_dma_continuous_data()`.
For the scatter-gather buffers, use ``SNDRV_DMA_TYPE_DEV_SG`` with the
device pointer (see the `Non-Contiguous Buffers`_ section).
Once the buffer is pre-allocated, you can use the allocator in the Once the buffer is pre-allocated, you can use the allocator in the
``hw_params`` callback: ``hw_params`` callback:

Просмотреть файл

@ -99,6 +99,13 @@ static void snd_free_dev_iram(struct snd_dma_buffer *dmab)
* *
*/ */
static inline gfp_t snd_mem_get_gfp_flags(const struct device *dev)
{
if (!dev)
return GFP_KERNEL;
else
return (__force gfp_t)(unsigned long)dev;
}
/** /**
* snd_dma_alloc_pages - allocate the buffer area according to the given type * snd_dma_alloc_pages - allocate the buffer area according to the given type
@ -120,8 +127,6 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
return -ENXIO; return -ENXIO;
if (WARN_ON(!dmab)) if (WARN_ON(!dmab))
return -ENXIO; return -ENXIO;
if (WARN_ON(!device))
return -EINVAL;
dmab->dev.type = type; dmab->dev.type = type;
dmab->dev.dev = device; dmab->dev.dev = device;
@ -129,7 +134,7 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
switch (type) { switch (type) {
case SNDRV_DMA_TYPE_CONTINUOUS: case SNDRV_DMA_TYPE_CONTINUOUS:
dmab->area = alloc_pages_exact(size, dmab->area = alloc_pages_exact(size,
(__force gfp_t)(unsigned long)device); snd_mem_get_gfp_flags(device));
dmab->addr = 0; dmab->addr = 0;
break; break;
#ifdef CONFIG_HAS_DMA #ifdef CONFIG_HAS_DMA