diff options
author | Heesub Shin <heesub.shin@samsung.com> | 2014-05-28 02:52:52 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-05-29 16:40:33 -0400 |
commit | 792407484a09b455064722c5190b45e1e1f2cecd (patch) | |
tree | 0dd784ef22532b372da005c639e1f41a963071d7 | |
parent | f9de4a30a5e647bff71509d6f5d419f6967ba291 (diff) |
staging: ion: tidy up a bit
For aesthetics and readability, rename goto labels, remove
useless code lines, and clarify function return type.
Signed-off-by: Heesub Shin <heesub.shin@samsung.com>
Reviewed-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Tested-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/staging/android/ion/ion_page_pool.c | 2 | ||||
-rw-r--r-- | drivers/staging/android/ion/ion_priv.h | 2 | ||||
-rw-r--r-- | drivers/staging/android/ion/ion_system_heap.c | 57 |
3 files changed, 28 insertions, 33 deletions
diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c index ecb5fc34ec5c..ead405458c75 100644 --- a/drivers/staging/android/ion/ion_page_pool.c +++ b/drivers/staging/android/ion/ion_page_pool.c | |||
@@ -89,7 +89,7 @@ static struct page *ion_page_pool_remove(struct ion_page_pool *pool, bool high) | |||
89 | return page; | 89 | return page; |
90 | } | 90 | } |
91 | 91 | ||
92 | void *ion_page_pool_alloc(struct ion_page_pool *pool) | 92 | struct page *ion_page_pool_alloc(struct ion_page_pool *pool) |
93 | { | 93 | { |
94 | struct page *page = NULL; | 94 | struct page *page = NULL; |
95 | 95 | ||
diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index c2dc942418bf..c8f01757abfa 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h | |||
@@ -378,7 +378,7 @@ struct ion_page_pool { | |||
378 | 378 | ||
379 | struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order); | 379 | struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order); |
380 | void ion_page_pool_destroy(struct ion_page_pool *); | 380 | void ion_page_pool_destroy(struct ion_page_pool *); |
381 | void *ion_page_pool_alloc(struct ion_page_pool *); | 381 | struct page *ion_page_pool_alloc(struct ion_page_pool *); |
382 | void ion_page_pool_free(struct ion_page_pool *, struct page *); | 382 | void ion_page_pool_free(struct ion_page_pool *, struct page *); |
383 | 383 | ||
384 | /** ion_page_pool_shrink - shrinks the size of the memory cached in the pool | 384 | /** ion_page_pool_shrink - shrinks the size of the memory cached in the pool |
diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index a14499514eb6..ae3c9ed59b09 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c | |||
@@ -42,7 +42,7 @@ static int order_to_index(unsigned int order) | |||
42 | return -1; | 42 | return -1; |
43 | } | 43 | } |
44 | 44 | ||
45 | static unsigned int order_to_size(int order) | 45 | static inline unsigned int order_to_size(int order) |
46 | { | 46 | { |
47 | return PAGE_SIZE << order; | 47 | return PAGE_SIZE << order; |
48 | } | 48 | } |
@@ -79,8 +79,6 @@ static struct page *alloc_buffer_page(struct ion_system_heap *heap, | |||
79 | ion_pages_sync_for_device(NULL, page, PAGE_SIZE << order, | 79 | ion_pages_sync_for_device(NULL, page, PAGE_SIZE << order, |
80 | DMA_BIDIRECTIONAL); | 80 | DMA_BIDIRECTIONAL); |
81 | } | 81 | } |
82 | if (!page) | ||
83 | return NULL; | ||
84 | 82 | ||
85 | return page; | 83 | return page; |
86 | } | 84 | } |
@@ -126,7 +124,6 @@ static struct page_info *alloc_largest_available(struct ion_system_heap *heap, | |||
126 | 124 | ||
127 | info->page = page; | 125 | info->page = page; |
128 | info->order = orders[i]; | 126 | info->order = orders[i]; |
129 | INIT_LIST_HEAD(&info->list); | ||
130 | return info; | 127 | return info; |
131 | } | 128 | } |
132 | kfree(info); | 129 | kfree(info); |
@@ -144,7 +141,6 @@ static int ion_system_heap_allocate(struct ion_heap *heap, | |||
144 | heap); | 141 | heap); |
145 | struct sg_table *table; | 142 | struct sg_table *table; |
146 | struct scatterlist *sg; | 143 | struct scatterlist *sg; |
147 | int ret; | ||
148 | struct list_head pages; | 144 | struct list_head pages; |
149 | struct page_info *info, *tmp_info; | 145 | struct page_info *info, *tmp_info; |
150 | int i = 0; | 146 | int i = 0; |
@@ -162,24 +158,23 @@ static int ion_system_heap_allocate(struct ion_heap *heap, | |||
162 | info = alloc_largest_available(sys_heap, buffer, size_remaining, | 158 | info = alloc_largest_available(sys_heap, buffer, size_remaining, |
163 | max_order); | 159 | max_order); |
164 | if (!info) | 160 | if (!info) |
165 | goto err; | 161 | goto free_pages; |
166 | list_add_tail(&info->list, &pages); | 162 | list_add_tail(&info->list, &pages); |
167 | size_remaining -= (1 << info->order) * PAGE_SIZE; | 163 | size_remaining -= PAGE_SIZE << info->order; |
168 | max_order = info->order; | 164 | max_order = info->order; |
169 | i++; | 165 | i++; |
170 | } | 166 | } |
171 | table = kmalloc(sizeof(struct sg_table), GFP_KERNEL); | 167 | table = kmalloc(sizeof(struct sg_table), GFP_KERNEL); |
172 | if (!table) | 168 | if (!table) |
173 | goto err; | 169 | goto free_pages; |
174 | 170 | ||
175 | ret = sg_alloc_table(table, i, GFP_KERNEL); | 171 | if (sg_alloc_table(table, i, GFP_KERNEL)) |
176 | if (ret) | 172 | goto free_table; |
177 | goto err1; | ||
178 | 173 | ||
179 | sg = table->sgl; | 174 | sg = table->sgl; |
180 | list_for_each_entry_safe(info, tmp_info, &pages, list) { | 175 | list_for_each_entry_safe(info, tmp_info, &pages, list) { |
181 | struct page *page = info->page; | 176 | struct page *page = info->page; |
182 | sg_set_page(sg, page, (1 << info->order) * PAGE_SIZE, 0); | 177 | sg_set_page(sg, page, PAGE_SIZE << info->order, 0); |
183 | sg = sg_next(sg); | 178 | sg = sg_next(sg); |
184 | list_del(&info->list); | 179 | list_del(&info->list); |
185 | kfree(info); | 180 | kfree(info); |
@@ -187,9 +182,10 @@ static int ion_system_heap_allocate(struct ion_heap *heap, | |||
187 | 182 | ||
188 | buffer->priv_virt = table; | 183 | buffer->priv_virt = table; |
189 | return 0; | 184 | return 0; |
190 | err1: | 185 | |
186 | free_table: | ||
191 | kfree(table); | 187 | kfree(table); |
192 | err: | 188 | free_pages: |
193 | list_for_each_entry_safe(info, tmp_info, &pages, list) { | 189 | list_for_each_entry_safe(info, tmp_info, &pages, list) { |
194 | free_buffer_page(sys_heap, buffer, info->page, info->order); | 190 | free_buffer_page(sys_heap, buffer, info->page, info->order); |
195 | kfree(info); | 191 | kfree(info); |
@@ -199,14 +195,12 @@ err: | |||
199 | 195 | ||
200 | static void ion_system_heap_free(struct ion_buffer *buffer) | 196 | static void ion_system_heap_free(struct ion_buffer *buffer) |
201 | { | 197 | { |
202 | struct ion_heap *heap = buffer->heap; | 198 | struct ion_system_heap *sys_heap = container_of(buffer->heap, |
203 | struct ion_system_heap *sys_heap = container_of(heap, | ||
204 | struct ion_system_heap, | 199 | struct ion_system_heap, |
205 | heap); | 200 | heap); |
206 | struct sg_table *table = buffer->sg_table; | 201 | struct sg_table *table = buffer->sg_table; |
207 | bool cached = ion_buffer_cached(buffer); | 202 | bool cached = ion_buffer_cached(buffer); |
208 | struct scatterlist *sg; | 203 | struct scatterlist *sg; |
209 | LIST_HEAD(pages); | ||
210 | int i; | 204 | int i; |
211 | 205 | ||
212 | /* uncached pages come from the page pools, zero them before returning | 206 | /* uncached pages come from the page pools, zero them before returning |
@@ -276,10 +270,10 @@ static int ion_system_heap_debug_show(struct ion_heap *heap, struct seq_file *s, | |||
276 | 270 | ||
277 | seq_printf(s, "%d order %u highmem pages in pool = %lu total\n", | 271 | seq_printf(s, "%d order %u highmem pages in pool = %lu total\n", |
278 | pool->high_count, pool->order, | 272 | pool->high_count, pool->order, |
279 | (1 << pool->order) * PAGE_SIZE * pool->high_count); | 273 | (PAGE_SIZE << pool->order) * pool->high_count); |
280 | seq_printf(s, "%d order %u lowmem pages in pool = %lu total\n", | 274 | seq_printf(s, "%d order %u lowmem pages in pool = %lu total\n", |
281 | pool->low_count, pool->order, | 275 | pool->low_count, pool->order, |
282 | (1 << pool->order) * PAGE_SIZE * pool->low_count); | 276 | (PAGE_SIZE << pool->order) * pool->low_count); |
283 | } | 277 | } |
284 | return 0; | 278 | return 0; |
285 | } | 279 | } |
@@ -298,7 +292,7 @@ struct ion_heap *ion_system_heap_create(struct ion_platform_heap *unused) | |||
298 | heap->pools = kzalloc(sizeof(struct ion_page_pool *) * num_orders, | 292 | heap->pools = kzalloc(sizeof(struct ion_page_pool *) * num_orders, |
299 | GFP_KERNEL); | 293 | GFP_KERNEL); |
300 | if (!heap->pools) | 294 | if (!heap->pools) |
301 | goto err_alloc_pools; | 295 | goto free_heap; |
302 | for (i = 0; i < num_orders; i++) { | 296 | for (i = 0; i < num_orders; i++) { |
303 | struct ion_page_pool *pool; | 297 | struct ion_page_pool *pool; |
304 | gfp_t gfp_flags = low_order_gfp_flags; | 298 | gfp_t gfp_flags = low_order_gfp_flags; |
@@ -307,18 +301,18 @@ struct ion_heap *ion_system_heap_create(struct ion_platform_heap *unused) | |||
307 | gfp_flags = high_order_gfp_flags; | 301 | gfp_flags = high_order_gfp_flags; |
308 | pool = ion_page_pool_create(gfp_flags, orders[i]); | 302 | pool = ion_page_pool_create(gfp_flags, orders[i]); |
309 | if (!pool) | 303 | if (!pool) |
310 | goto err_create_pool; | 304 | goto destroy_pools; |
311 | heap->pools[i] = pool; | 305 | heap->pools[i] = pool; |
312 | } | 306 | } |
313 | 307 | ||
314 | heap->heap.debug_show = ion_system_heap_debug_show; | 308 | heap->heap.debug_show = ion_system_heap_debug_show; |
315 | return &heap->heap; | 309 | return &heap->heap; |
316 | err_create_pool: | 310 | |
317 | for (i = 0; i < num_orders; i++) | 311 | destroy_pools: |
318 | if (heap->pools[i]) | 312 | while (i--) |
319 | ion_page_pool_destroy(heap->pools[i]); | 313 | ion_page_pool_destroy(heap->pools[i]); |
320 | kfree(heap->pools); | 314 | kfree(heap->pools); |
321 | err_alloc_pools: | 315 | free_heap: |
322 | kfree(heap); | 316 | kfree(heap); |
323 | return ERR_PTR(-ENOMEM); | 317 | return ERR_PTR(-ENOMEM); |
324 | } | 318 | } |
@@ -364,12 +358,12 @@ static int ion_system_contig_heap_allocate(struct ion_heap *heap, | |||
364 | table = kmalloc(sizeof(struct sg_table), GFP_KERNEL); | 358 | table = kmalloc(sizeof(struct sg_table), GFP_KERNEL); |
365 | if (!table) { | 359 | if (!table) { |
366 | ret = -ENOMEM; | 360 | ret = -ENOMEM; |
367 | goto out; | 361 | goto free_pages; |
368 | } | 362 | } |
369 | 363 | ||
370 | ret = sg_alloc_table(table, 1, GFP_KERNEL); | 364 | ret = sg_alloc_table(table, 1, GFP_KERNEL); |
371 | if (ret) | 365 | if (ret) |
372 | goto out; | 366 | goto free_table; |
373 | 367 | ||
374 | sg_set_page(table->sgl, page, len, 0); | 368 | sg_set_page(table->sgl, page, len, 0); |
375 | 369 | ||
@@ -379,10 +373,12 @@ static int ion_system_contig_heap_allocate(struct ion_heap *heap, | |||
379 | 373 | ||
380 | return 0; | 374 | return 0; |
381 | 375 | ||
382 | out: | 376 | free_table: |
377 | kfree(table); | ||
378 | free_pages: | ||
383 | for (i = 0; i < len >> PAGE_SHIFT; i++) | 379 | for (i = 0; i < len >> PAGE_SHIFT; i++) |
384 | __free_page(page + i); | 380 | __free_page(page + i); |
385 | kfree(table); | 381 | |
386 | return ret; | 382 | return ret; |
387 | } | 383 | } |
388 | 384 | ||
@@ -448,4 +444,3 @@ void ion_system_contig_heap_destroy(struct ion_heap *heap) | |||
448 | { | 444 | { |
449 | kfree(heap); | 445 | kfree(heap); |
450 | } | 446 | } |
451 | |||