浏览代码

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>
Takashi Iwai 17 年之前
父节点
当前提交
4e184f8fc0
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      sound/core/memalloc.c

+ 6 - 1
sound/core/memalloc.c

@@ -277,11 +277,16 @@ int snd_dma_alloc_pages_fallback(int type, struct device *device, size_t size,
 	int err;
 	int err;
 
 
 	while ((err = snd_dma_alloc_pages(type, device, size, dmab)) < 0) {
 	while ((err = snd_dma_alloc_pages(type, device, size, dmab)) < 0) {
+		size_t aligned_size;
 		if (err != -ENOMEM)
 		if (err != -ENOMEM)
 			return err;
 			return err;
-		size >>= 1;
 		if (size <= PAGE_SIZE)
 		if (size <= PAGE_SIZE)
 			return -ENOMEM;
 			return -ENOMEM;
+		aligned_size = PAGE_SIZE << get_order(size);
+		if (size != aligned_size)
+			size = aligned_size;
+		else
+			size >>= 1;
 	}
 	}
 	if (! dmab->area)
 	if (! dmab->area)
 		return -ENOMEM;
 		return -ENOMEM;