From bdd43cb39f1b1e897c5d7992d05d0b9f0dd786d1 Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Wed, 5 Sep 2012 07:50:41 +0200 Subject: [PATCH 1/3] 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 [fixed compilation break caused by missing semicolon] Signed-off-by: Marek Szyprowski --- drivers/base/dma-contiguous.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c index 34d94c762a1e..9a1469474f55 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; } /** From 5a796eeb7bbacc628044b12a2d000167ddbabec8 Mon Sep 17 00:00:00 2001 From: Hiroshi Doyu Date: Tue, 11 Sep 2012 07:39:39 +0200 Subject: [PATCH 2/3] ARM: dma-mapping: Small logical clean up Skip unnecessary operations if order == 0. A little bit easier to read. Signed-off-by: Hiroshi Doyu Signed-off-by: Marek Szyprowski --- arch/arm/mm/dma-mapping.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 13f555d62491..c390cea6a258 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1012,11 +1012,12 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, gfp_t if (!pages[i]) goto error; - if (order) + if (order) { split_page(pages[i], order); - j = 1 << order; - while (--j) - pages[i + j] = pages[i] + j; + j = 1 << order; + while (--j) + pages[i + j] = pages[i] + j; + } __dma_clear_buffer(pages[i], PAGE_SIZE << order); i += 1 << order; From 75c5971614932ca53009cbbdfd6c8f96eab9e46f Mon Sep 17 00:00:00 2001 From: Hiroshi Doyu Date: Tue, 11 Sep 2012 07:39:48 +0200 Subject: [PATCH 3/3] ARM: dma-mapping: Refrain noisy console message With many IOMMU'able devices, console gets noisy. Tegra30 has a few dozen of IOMMU'able devices. Signed-off-by: Hiroshi Doyu Signed-off-by: Marek Szyprowski --- arch/arm/mm/dma-mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index c390cea6a258..3819f029a40c 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1666,7 +1666,7 @@ int arm_iommu_attach_device(struct device *dev, dev->archdata.mapping = mapping; set_dma_ops(dev, &iommu_ops); - pr_info("Attached IOMMU controller to %s device.\n", dev_name(dev)); + pr_debug("Attached IOMMU controller to %s device.\n", dev_name(dev)); return 0; }