ARM: dma-mapping: free allocated page if unable to map
authorRussell King <rmk+kernel@arm.linux.org.uk>
Thu, 22 Sep 2011 09:32:25 +0000 (10:32 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Mon, 26 Sep 2011 08:36:50 +0000 (09:36 +0100)
If the attempt to map a page for DMA fails (eg, because we're out of
mapping space) then we must not hold on to the page we allocated for
DMA - doing so will result in a memory leak.

Cc: <stable@kernel.org>
Reported-by: Bryan Phillippe <bp@darkforest.org>
Tested-by: Bryan Phillippe <bp@darkforest.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/mm/dma-mapping.c

index 0a0a1e7c20d2b2b7f459197be96575f757171cfd..c3ff82f92d9c812357f99ab7427a7788e718eb13 100644 (file)
@@ -324,6 +324,8 @@ __dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp,
 
        if (addr)
                *handle = pfn_to_dma(dev, page_to_pfn(page));
+       else
+               __dma_free_buffer(page, size);
 
        return addr;
 }