diff options
author | Andrew Morton <akpm@linux-foundation.org> | 2009-01-06 17:43:09 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-06 18:59:31 -0500 |
commit | eccd83e116e7f414a1da3aae3745384b7b171883 (patch) | |
tree | 3cc2e2778ecafa34be3380bc85ec9d72b94b5292 /kernel/dma-coherent.c | |
parent | 0bef3c2dc7d0c8238330785c8f4504761b0e370b (diff) |
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>
Diffstat (limited to 'kernel/dma-coherent.c')
-rw-r--r-- | kernel/dma-coherent.c | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/kernel/dma-coherent.c b/kernel/dma-coherent.c index 4bdcea822b45..8056d081609c 100644 --- a/kernel/dma-coherent.c +++ b/kernel/dma-coherent.c | |||
@@ -109,34 +109,38 @@ EXPORT_SYMBOL(dma_mark_declared_memory_occupied); | |||
109 | int dma_alloc_from_coherent(struct device *dev, ssize_t size, | 109 | int dma_alloc_from_coherent(struct device *dev, ssize_t size, |
110 | dma_addr_t *dma_handle, void **ret) | 110 | dma_addr_t *dma_handle, void **ret) |
111 | { | 111 | { |
112 | struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL; | 112 | struct dma_coherent_mem *mem; |
113 | int order = get_order(size); | 113 | int order = get_order(size); |
114 | int pageno; | ||
114 | 115 | ||
115 | if (mem) { | 116 | if (!dev) |
116 | int page = bitmap_find_free_region(mem->bitmap, mem->size, | 117 | return 0; |
117 | order); | 118 | mem = dev->dma_mem; |
118 | if (page >= 0) { | 119 | if (!mem) |
119 | /* | 120 | return 0; |
120 | * Memory was found in the per-device arena. | 121 | |
121 | */ | 122 | pageno = bitmap_find_free_region(mem->bitmap, mem->size, order); |
122 | *dma_handle = mem->device_base + (page << PAGE_SHIFT); | 123 | if (pageno >= 0) { |
123 | *ret = mem->virt_base + (page << PAGE_SHIFT); | 124 | /* |
124 | memset(*ret, 0, size); | 125 | * Memory was found in the per-device arena. |
125 | } else if (mem->flags & DMA_MEMORY_EXCLUSIVE) { | 126 | */ |
126 | /* | 127 | *dma_handle = mem->device_base + (pageno << PAGE_SHIFT); |
127 | * The per-device arena is exhausted and we are not | 128 | *ret = mem->virt_base + (pageno << PAGE_SHIFT); |
128 | * permitted to fall back to generic memory. | 129 | memset(*ret, 0, size); |
129 | */ | 130 | } else if (mem->flags & DMA_MEMORY_EXCLUSIVE) { |
130 | *ret = NULL; | 131 | /* |
131 | } else { | 132 | * The per-device arena is exhausted and we are not |
132 | /* | 133 | * permitted to fall back to generic memory. |
133 | * The per-device arena is exhausted and we are | 134 | */ |
134 | * permitted to fall back to generic memory. | 135 | *ret = NULL; |
135 | */ | 136 | } else { |
136 | return 0; | 137 | /* |
137 | } | 138 | * The per-device arena is exhausted and we are |
139 | * permitted to fall back to generic memory. | ||
140 | */ | ||
141 | return 0; | ||
138 | } | 142 | } |
139 | return (mem != NULL); | 143 | return 1; |
140 | } | 144 | } |
141 | EXPORT_SYMBOL(dma_alloc_from_coherent); | 145 | EXPORT_SYMBOL(dma_alloc_from_coherent); |
142 | 146 | ||