dma_alloc_coherent: clean it up
This thing was rather stupidly coded. Rework it all prior to making changes. Also, rename local variable `page': kernel readers expect something called `page' to have type `struct page *'. Cc: Guennadi Liakhovetski <lg@denx.de> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Pekka Enberg <penberg@cs.helsinki.fi> Cc: Dmitry Baryshkov <dbaryshkov@gmail.com> Cc: Jesse Barnes <jbarnes@virtuousgeek.org> Cc: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
committed by
Linus Torvalds
parent
0bef3c2dc7
commit
eccd83e116
@@ -109,34 +109,38 @@ EXPORT_SYMBOL(dma_mark_declared_memory_occupied);
|
|||||||
int dma_alloc_from_coherent(struct device *dev, ssize_t size,
|
int dma_alloc_from_coherent(struct device *dev, ssize_t size,
|
||||||
dma_addr_t *dma_handle, void **ret)
|
dma_addr_t *dma_handle, void **ret)
|
||||||
{
|
{
|
||||||
struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL;
|
struct dma_coherent_mem *mem;
|
||||||
int order = get_order(size);
|
int order = get_order(size);
|
||||||
|
int pageno;
|
||||||
|
|
||||||
if (mem) {
|
if (!dev)
|
||||||
int page = bitmap_find_free_region(mem->bitmap, mem->size,
|
return 0;
|
||||||
order);
|
mem = dev->dma_mem;
|
||||||
if (page >= 0) {
|
if (!mem)
|
||||||
/*
|
return 0;
|
||||||
* Memory was found in the per-device arena.
|
|
||||||
*/
|
pageno = bitmap_find_free_region(mem->bitmap, mem->size, order);
|
||||||
*dma_handle = mem->device_base + (page << PAGE_SHIFT);
|
if (pageno >= 0) {
|
||||||
*ret = mem->virt_base + (page << PAGE_SHIFT);
|
/*
|
||||||
memset(*ret, 0, size);
|
* Memory was found in the per-device arena.
|
||||||
} else if (mem->flags & DMA_MEMORY_EXCLUSIVE) {
|
*/
|
||||||
/*
|
*dma_handle = mem->device_base + (pageno << PAGE_SHIFT);
|
||||||
* The per-device arena is exhausted and we are not
|
*ret = mem->virt_base + (pageno << PAGE_SHIFT);
|
||||||
* permitted to fall back to generic memory.
|
memset(*ret, 0, size);
|
||||||
*/
|
} else if (mem->flags & DMA_MEMORY_EXCLUSIVE) {
|
||||||
*ret = NULL;
|
/*
|
||||||
} else {
|
* The per-device arena is exhausted and we are not
|
||||||
/*
|
* permitted to fall back to generic memory.
|
||||||
* The per-device arena is exhausted and we are
|
*/
|
||||||
* permitted to fall back to generic memory.
|
*ret = NULL;
|
||||||
*/
|
} else {
|
||||||
return 0;
|
/*
|
||||||
}
|
* The per-device arena is exhausted and we are
|
||||||
|
* permitted to fall back to generic memory.
|
||||||
|
*/
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return (mem != NULL);
|
return 1;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(dma_alloc_from_coherent);
|
EXPORT_SYMBOL(dma_alloc_from_coherent);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user