From patchwork Mon Feb 24 19:44:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11401455 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F92114D5 for ; Mon, 24 Feb 2020 19:45:07 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 594902080D for ; Mon, 24 Feb 2020 19:45:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jC3AiNoT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 594902080D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3h4kjU4XfZnr1SMvmd84srFAsnmIG2tBwGOGwd2aY4U=; b=jC3AiNoTKBmV5X PS/9qIUWx2z4rBjDql+/ftElZy+TevER1l8rwTRvmIQzp38F3JxYAt8XakJ4eyqSW1tAZa07De7Q6 HG1RSZQyaoQPnefcDqVomzobQXhryKsuTNiMFQ8LRbgluUq4wys+Ol3Ev7CHiixZsPRv8jCFV+fcj z+TH1iuHTnVzSH9w1mfLKtlJMioLijAdoxFKfUX2d1Bsyr3RqdO2k9uSG+QayVbJabM/8/MgRhZ2/ Jv387bdvdEwP8HuKUxxF6p0Ipenh+gfdZsxymTqMwNw684la54Xt6j8nBppd3GLI2oF8NlyOSWrB7 jyGK35Asykdld4MO7VwA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j6Jf2-0006fk-KM; Mon, 24 Feb 2020 19:45:00 +0000 Received: from [4.28.11.157] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1j6Jer-0006XE-BN; Mon, 24 Feb 2020 19:44:49 +0000 From: Christoph Hellwig To: Jonas Bonn , Stefan Kristiansson , Stafford Horne Subject: [PATCH 2/5] dma-direct: consolidate the error handling in dma_direct_alloc_pages Date: Mon, 24 Feb 2020 11:44:42 -0800 Message-Id: <20200224194446.690816-3-hch@lst.de> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200224194446.690816-1-hch@lst.de> References: <20200224194446.690816-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , linux-arch@vger.kernel.org, Robin Murphy , linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, openrisc@lists.librecores.org, Will Deacon , linux-arm-kernel@lists.infradead.org, Marek Szyprowski Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Use a goto label to merge two error return cases. Signed-off-by: Christoph Hellwig --- 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,