]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
ALSA: memalloc: Don't exceed over the requested size
authorTakashi Iwai <tiwai@suse.de>
Thu, 19 Jul 2018 09:01:04 +0000 (11:01 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 23 Jul 2018 07:06:33 +0000 (09:06 +0200)
snd_dma_alloc_pages_fallback() tries to allocate pages again when the
allocation fails with reduced size.  But the first try actually
*increases* the size to power-of-two, which may give back a larger
chunk than the requested size.  This confuses the callers, e.g. sgbuf
assumes that the size is equal or less, and it may result in a bad
loop due to the underflow and eventually lead to Oops.

The code of this function seems incorrectly assuming the usage of
get_order().  We need to decrease at first, then align to
power-of-two.

Reported-and-tested-by: he, bo <bo.he@intel.com>
Reported-by: zhang jun <jun.zhang@intel.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/memalloc.c

index 7f89d3c79a4b740b655342ebf4958d05fe6c6646..753d5fc4b284fa66cd0f3911d4096322fd7b3bf9 100644 (file)
@@ -242,16 +242,12 @@ 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;
                if (size <= PAGE_SIZE)
                        return -ENOMEM;
-               aligned_size = PAGE_SIZE << get_order(size);
-               if (size != aligned_size)
-                       size = aligned_size;
-               else
-                       size >>= 1;
+               size >>= 1;
+               size = PAGE_SIZE << get_order(size);
        }
        if (! dmab->area)
                return -ENOMEM;