From patchwork Mon Feb 11 13:35:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10805863 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E38A13B5 for ; Mon, 11 Feb 2019 13:40:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39FCA2A3A5 for ; Mon, 11 Feb 2019 13:40:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CFA82A53B; Mon, 11 Feb 2019 13:40:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SUSPICIOUS_RECIPS autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D5EB42A4D1 for ; Mon, 11 Feb 2019 13:40:05 +0000 (UTC) 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=d5BEplLtkmhYvU9KhZolwZdYcsuXbAWxmpKliK1W9Gw=; b=ssnhXtQL5yUSTe nvDyYv1UXjyaMfJj0xI0+yRHC4N4GrQG9bHT/YQWHNXNEmO6lZZasz25e3HQoVr4GPOmzxcMyQDcP eW7fJ3GaC7laQB8hLOFVmoBdoLip+5vUJHVCF6L6JzlRjxOhnfvIWxxZX+NxKpRDYev6+M5r/ryVg xTrmNN75wRGu6sdrDC45UP57qGkmIVld0wCzjMHIB+soFRvxZsrpoDexP1yVcSYTJFczpxLW4owW7 Oi603Dh/Aqum0qRWs7SiJSNbUgBWkhaYLtVzV+L1y68iMFBHTXorpSXiagViLXvS69jm4Kk9MOZ5h DKa4LxViSATa3NYa9G/Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gtBoY-0003gP-Md; Mon, 11 Feb 2019 13:40:02 +0000 Received: from 089144210182.atnat0019.highway.a1.net ([89.144.210.182] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gtBlA-0000WC-MV; Mon, 11 Feb 2019 13:36:33 +0000 From: Christoph Hellwig To: iommu@lists.linux-foundation.org Subject: [PATCH 12/12] dma-mapping: remove dma_assign_coherent_memory Date: Mon, 11 Feb 2019 14:35:54 +0100 Message-Id: <20190211133554.30055-13-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211133554.30055-1-hch@lst.de> References: <20190211133554.30055-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-xtensa@linux-xtensa.org, linuxppc-dev@lists.ozlabs.org, linux-sh@vger.kernel.org, Greg Kroah-Hartman , x86@kernel.org, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-riscv@lists.infradead.org, linux-snps-arc@lists.infradead.org, Lee Jones , linux-arm-kernel@lists.infradead.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The only useful bit in this function was the already assigned check. Once that is moved to dma_init_coherent_memory thee rest can easily be handled in the two callers. Signed-off-by: Christoph Hellwig --- kernel/dma/coherent.c | 47 +++++++++++++------------------------------ 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c index d7a27008f228..1e3ce71cd993 100644 --- a/kernel/dma/coherent.c +++ b/kernel/dma/coherent.c @@ -41,6 +41,9 @@ static int dma_init_coherent_memory(phys_addr_t phys_addr, int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long); int ret; + if (*mem) + return -EBUSY; + if (!size) { ret = -EINVAL; goto out; @@ -88,33 +91,11 @@ static void dma_release_coherent_memory(struct dma_coherent_mem *mem) kfree(mem); } -static int dma_assign_coherent_memory(struct device *dev, - struct dma_coherent_mem *mem) -{ - if (!dev) - return -ENODEV; - - if (dev->dma_mem) - return -EBUSY; - - dev->dma_mem = mem; - return 0; -} - int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, dma_addr_t device_addr, size_t size) { - struct dma_coherent_mem *mem; - int ret; - - ret = dma_init_coherent_memory(phys_addr, device_addr, size, &mem); - if (ret) - return ret; - - ret = dma_assign_coherent_memory(dev, mem); - if (ret) - dma_release_coherent_memory(mem); - return ret; + return dma_init_coherent_memory(phys_addr, device_addr, size, + &dev->dma_mem); } EXPORT_SYMBOL(dma_declare_coherent_memory); @@ -238,18 +219,18 @@ static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev) struct dma_coherent_mem *mem = rmem->priv; int ret; - if (!mem) { - ret = dma_init_coherent_memory(rmem->base, rmem->base, - rmem->size, &mem); - if (ret) { - pr_err("Reserved memory: failed to init DMA memory pool at %pa, size %ld MiB\n", - &rmem->base, (unsigned long)rmem->size / SZ_1M); - return ret; - } + ret = dma_init_coherent_memory(rmem->base, rmem->base, rmem->size, + &mem); + if (ret && ret != -EBUSY) { + pr_err("Reserved memory: failed to init DMA memory pool at %pa, size %ld MiB\n", + &rmem->base, (unsigned long)rmem->size / SZ_1M); + return ret; } + mem->use_dev_dma_pfn_offset = true; + if (dev) + dev->dma_mem = mem; rmem->priv = mem; - dma_assign_coherent_memory(dev, mem); return 0; }