From: Christoph Hellwig <hch@lst.de>
To: Jonas Bonn <jonas@southpole.se>,
Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>,
Stafford Horne <shorne@gmail.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
Robin Murphy <robin.murphy@arm.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
openrisc@lists.librecores.org, iommu@lists.linux-foundation.org,
linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/5] dma-direct: consolidate the error handling in dma_direct_alloc_pages
Date: Mon, 24 Feb 2020 11:44:42 -0800 [thread overview]
Message-ID: <20200224194446.690816-3-hch@lst.de> (raw)
In-Reply-To: <20200224194446.690816-1-hch@lst.de>
Use a goto label to merge two error return cases.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
kernel/dma/direct.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index ac7956c38f69..9dfcc7be4903 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -157,11 +157,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;
}
@@ -174,8 +171,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);
@@ -195,6 +191,9 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
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,
--
2.24.1
next prev parent reply other threads:[~2020-02-24 19:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-24 19:44 provide in-place uncached remapping for dma-direct v2 Christoph Hellwig
2020-02-24 19:44 ` Christoph Hellwig
2020-02-24 19:44 ` [PATCH 1/5] dma-direct: remove the cached_kernel_address hook Christoph Hellwig
2020-02-24 19:44 ` Christoph Hellwig
2020-02-24 19:44 ` Christoph Hellwig [this message]
2020-02-24 19:44 ` [PATCH 2/5] dma-direct: consolidate the error handling in dma_direct_alloc_pages Christoph Hellwig
2020-02-24 19:44 ` [PATCH 3/5] dma-direct: make uncached_kernel_address more general Christoph Hellwig
2020-02-24 19:44 ` [PATCH 4/5] dma-direct: provide a arch_dma_clear_uncached hook Christoph Hellwig
2020-02-24 21:53 ` Ira Weiny
2020-02-24 21:56 ` Christoph Hellwig
2020-02-24 19:44 ` [PATCH 5/5] openrisc: use the generic in-place uncached DMA allocator Christoph Hellwig
2020-02-24 19:44 ` Christoph Hellwig
2020-02-25 10:09 ` Stafford Horne
2020-03-02 16:05 ` provide in-place uncached remapping for dma-direct v2 Robin Murphy
2020-03-02 16:05 ` Robin Murphy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200224194446.690816-3-hch@lst.de \
--to=hch@lst.de \
--cc=iommu@lists.linux-foundation.org \
--cc=jonas@southpole.se \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mark.rutland@arm.com \
--cc=openrisc@lists.librecores.org \
--cc=robin.murphy@arm.com \
--cc=shorne@gmail.com \
--cc=stefan.kristiansson@saunalahti.fi \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).