dma-direct: consolidate the error handling in dma_direct_alloc_pages
authorChristoph Hellwig <hch@lst.de>
Fri, 21 Feb 2020 20:26:00 +0000 (12:26 -0800)
committerChristoph Hellwig <hch@lst.de>
Mon, 16 Mar 2020 09:48:06 +0000 (10:48 +0100)
Use a goto label to merge two error return cases.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
kernel/dma/direct.c

index 6af7ae83c4ada1534bcf7dc203de907515e24fea..650580fbbff3560e6dc538d86cd7a91d15462d3d 100644 (file)
@@ -169,11 +169,8 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
                ret = dma_common_contiguous_remap(page, PAGE_ALIGN(size),
                                dma_pgprot(dev, PAGE_KERNEL, attrs),
                                __builtin_return_address(0));
-               if (!ret) {
-                       dma_free_contiguous(dev, page, size);
-                       return ret;
-               }
-
+               if (!ret)
+                       goto out_free_pages;
                memset(ret, 0, size);
                goto done;
        }
@@ -186,8 +183,7 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
                 * so log an error and fail.
                 */
                dev_info(dev, "Rejecting highmem page from CMA.\n");
-               dma_free_contiguous(dev, page, size);
-               return NULL;
+               goto out_free_pages;
        }
 
        ret = page_address(page);
@@ -207,6 +203,9 @@ done:
        else
                *dma_handle = phys_to_dma(dev, page_to_phys(page));
        return ret;
+out_free_pages:
+       dma_free_contiguous(dev, page, size);
+       return NULL;
 }
 
 void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr,