Skip to content

Commit

Permalink
ALSA: Fix allocation size calculation in snd_dma_alloc_pages_fallback()
Browse files Browse the repository at this point in the history
snd_dma_alloc_pages_fallback() always tries to reduce the size in a half,
but it's not good when the given size isn't a power-of-two.
Check it first then try to align.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
  • Loading branch information
Takashi Iwai authored and Jaroslav Kysela committed Aug 25, 2008
1 parent 77a23f2 commit 4e184f8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sound/core/memalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,16 @@ int snd_dma_alloc_pages_fallback(int type, struct device *device, size_t size,
int err;

while ((err = snd_dma_alloc_pages(type, device, size, dmab)) < 0) {
size_t aligned_size;
if (err != -ENOMEM)
return err;
size >>= 1;
if (size <= PAGE_SIZE)
return -ENOMEM;
aligned_size = PAGE_SIZE << get_order(size);
if (size != aligned_size)
size = aligned_size;
else
size >>= 1;
}
if (! dmab->area)
return -ENOMEM;
Expand Down

0 comments on commit 4e184f8

Please sign in to comment.