提交 04da5694 编写于 作者: R Russell King

ARM: dma-mapping: fix nommu dma_alloc_coherent()

The nommu version of dma_alloc_coherent was using kmalloc/kfree to manage
the memory.  dma_alloc_coherent() is expected to work with a granularity
of a page, so this is wrong.  Fix it by using the helper functions now
provided.
Signed-off-by: NRussell King <rmk+kernel@arm.linux.org.uk>
Acked-by: NGreg Ungerer <gerg@uclinux.org>
上级 3e82d012
...@@ -212,24 +212,17 @@ static void * ...@@ -212,24 +212,17 @@ static void *
__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp, __dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp,
pgprot_t prot) pgprot_t prot)
{ {
void *virt; struct page *page;
u64 mask = get_coherent_dma_mask(dev);
if (!mask)
goto error;
if (mask < 0xffffffffULL) *handle = ~0;
gfp |= GFP_DMA; size = PAGE_ALIGN(size);
virt = kmalloc(size, gfp);
if (!virt)
goto error;
*handle = virt_to_dma(dev, virt); page = __dma_alloc_buffer(dev, size, gfp);
return virt; if (!page)
return NULL;
error: *handle = page_to_dma(dev, page);
*handle = ~0; return page_address(page);
return NULL;
} }
#endif /* CONFIG_MMU */ #endif /* CONFIG_MMU */
...@@ -406,7 +399,7 @@ void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr ...@@ -406,7 +399,7 @@ void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr
{ {
if (dma_release_from_coherent(dev, get_order(size), cpu_addr)) if (dma_release_from_coherent(dev, get_order(size), cpu_addr))
return; return;
kfree(cpu_addr); __dma_free_buffer(dma_to_page(dev, handle), PAGE_ALIGN(size));
} }
#endif /* CONFIG_MMU */ #endif /* CONFIG_MMU */
EXPORT_SYMBOL(dma_free_coherent); EXPORT_SYMBOL(dma_free_coherent);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册