aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Nazarewicz <mina86@mina86.com>2012-09-05 07:50:41 +0200
committerCyril Chemparathy <cyril@ti.com>2012-09-21 10:44:22 -0400
commit6287018d9798f85b28c0ed9e804724080d736590 (patch)
tree3d972fb8a89eece70a079241baa82050e35f9150
parent1003e91f49c18dc105d533a8e28f5ad870f31261 (diff)
downloadlinux-keystone-6287018d9798f85b28c0ed9e804724080d736590.tar.gz
drivers: dma-contiguous: refactor dma_alloc_from_contiguous()
The dma_alloc_from_contiguous() function returns either a valid pointer to a page structure or NULL, the error code set when pageno >= cma->count is not used at all and can be safely removed. This commit also changes the function to avoid goto and have only one exit path and one place where mutex is unlocked. Signed-off-by: Michal Nazarewicz <mina86@mina86.com> [fixed compilation break caused by missing semicolon] Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
-rw-r--r--drivers/base/dma-contiguous.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
index 456960a8a6fb7e..e79375346be870 100644
--- a/drivers/base/dma-contiguous.c
+++ b/drivers/base/dma-contiguous.c
@@ -315,6 +315,7 @@ struct page *dma_alloc_from_contiguous(struct device *dev, int count,
{
unsigned long mask, pfn, pageno, start = 0;
struct cma *cma = dev_get_cma_area(dev);
+ struct page *page = NULL;
int ret;
if (!cma || !cma->count)
@@ -336,18 +337,17 @@ struct page *dma_alloc_from_contiguous(struct device *dev, int count,
for (;;) {
pageno = bitmap_find_next_zero_area(cma->bitmap, cma->count,
start, count, mask);
- if (pageno >= cma->count) {
- ret = -ENOMEM;
- goto error;
- }
+ if (pageno >= cma->count)
+ break;
pfn = cma->base_pfn + pageno;
ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA);
if (ret == 0) {
bitmap_set(cma->bitmap, pageno, count);
+ page = pfn_to_page(pfn);
break;
} else if (ret != -EBUSY) {
- goto error;
+ break;
}
pr_debug("%s(): memory range at %p is busy, retrying\n",
__func__, pfn_to_page(pfn));
@@ -356,12 +356,8 @@ struct page *dma_alloc_from_contiguous(struct device *dev, int count,
}
mutex_unlock(&cma_mutex);
-
- pr_debug("%s(): returned %p\n", __func__, pfn_to_page(pfn));
- return pfn_to_page(pfn);
-error:
- mutex_unlock(&cma_mutex);
- return NULL;
+ pr_debug("%s(): returned %p\n", __func__, page);
+ return page;
}
/**