Commit 28f3f4f6 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: memalloc: Simplify snd_malloc_dev_pages() calls

snd_malloc_dev_pages() and snd_free_dev_pages() are local functions
and the parameters passed there are all contained in snd_dma_buffer
object.  As a code-simplification, pass snd_dma_buffer object and
assign the address there like other allocators do (except for
snd_malloc_pages() which is called from outside, hence we can't change
easily).

Only code refactoring, no functional changes.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 03486830
...@@ -82,26 +82,22 @@ EXPORT_SYMBOL(snd_free_pages); ...@@ -82,26 +82,22 @@ EXPORT_SYMBOL(snd_free_pages);
#ifdef CONFIG_HAS_DMA #ifdef CONFIG_HAS_DMA
/* allocate the coherent DMA pages */ /* allocate the coherent DMA pages */
static void *snd_malloc_dev_pages(struct device *dev, size_t size, dma_addr_t *dma) static void snd_malloc_dev_pages(struct snd_dma_buffer *dmab, size_t size)
{ {
gfp_t gfp_flags; gfp_t gfp_flags;
if (WARN_ON(!dma))
return NULL;
gfp_flags = GFP_KERNEL gfp_flags = GFP_KERNEL
| __GFP_COMP /* compound page lets parts be mapped */ | __GFP_COMP /* compound page lets parts be mapped */
| __GFP_NORETRY /* don't trigger OOM-killer */ | __GFP_NORETRY /* don't trigger OOM-killer */
| __GFP_NOWARN; /* no stack trace print - this call is non-critical */ | __GFP_NOWARN; /* no stack trace print - this call is non-critical */
return dma_alloc_coherent(dev, size, dma, gfp_flags); dmab->area = dma_alloc_coherent(dmab->dev.dev, size, &dmab->addr,
gfp_flags);
} }
/* free the coherent DMA pages */ /* free the coherent DMA pages */
static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr, static void snd_free_dev_pages(struct snd_dma_buffer *dmab)
dma_addr_t dma)
{ {
if (ptr == NULL) dma_free_coherent(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr);
return;
dma_free_coherent(dev, size, ptr, dma);
} }
#ifdef CONFIG_GENERIC_ALLOCATOR #ifdef CONFIG_GENERIC_ALLOCATOR
...@@ -195,7 +191,7 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size, ...@@ -195,7 +191,7 @@ int snd_dma_alloc_pages(int type, struct device *device, size_t size,
dmab->dev.type = SNDRV_DMA_TYPE_DEV; dmab->dev.type = SNDRV_DMA_TYPE_DEV;
#endif /* CONFIG_GENERIC_ALLOCATOR */ #endif /* CONFIG_GENERIC_ALLOCATOR */
case SNDRV_DMA_TYPE_DEV: case SNDRV_DMA_TYPE_DEV:
dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr); snd_malloc_dev_pages(dmab, size);
break; break;
#endif #endif
#ifdef CONFIG_SND_DMA_SGBUF #ifdef CONFIG_SND_DMA_SGBUF
...@@ -270,7 +266,7 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab) ...@@ -270,7 +266,7 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab)
break; break;
#endif /* CONFIG_GENERIC_ALLOCATOR */ #endif /* CONFIG_GENERIC_ALLOCATOR */
case SNDRV_DMA_TYPE_DEV: case SNDRV_DMA_TYPE_DEV:
snd_free_dev_pages(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr); snd_free_dev_pages(dmab);
break; break;
#endif #endif
#ifdef CONFIG_SND_DMA_SGBUF #ifdef CONFIG_SND_DMA_SGBUF
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment