Skip to content

Commit 4e184f8

Browse files
tiwaiperexg
authored andcommitted
ALSA: Fix allocation size calculation in snd_dma_alloc_pages_fallback()
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>
1 parent 77a23f2 commit 4e184f8

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎sound/core/memalloc.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,16 @@ int snd_dma_alloc_pages_fallback(int type, struct device *device, size_t size,
277277
int err;
278278

279279
while ((err = snd_dma_alloc_pages(type, device, size, dmab)) < 0) {
280+
size_t aligned_size;
280281
if (err != -ENOMEM)
281282
return err;
282-
size >>= 1;
283283
if (size <= PAGE_SIZE)
284284
return -ENOMEM;
285+
aligned_size = PAGE_SIZE << get_order(size);
286+
if (size != aligned_size)
287+
size = aligned_size;
288+
else
289+
size >>= 1;
285290
}
286291
if (! dmab->area)
287292
return -ENOMEM;

0 commit comments

Comments
 (0)