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: 10805859 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 008B013B5 for ; Mon, 11 Feb 2019 13:39:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E21232A225 for ; Mon, 11 Feb 2019 13:39:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5CE22A257; Mon, 11 Feb 2019 13:39:48 +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 745CD2A225 for ; Mon, 11 Feb 2019 13:39:48 +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=a5D7yfbg8TOIDzJLDcq2t0qeh3AnAArT7ZSGUG/RIO8=; b=S3e9jUlf2R2zbY 3pgVEZqIjn93pvbi6DG1RBxVsz1VJJOmTVZrMd/Y50sSyp+FEc34KU7hPDzWTe1H4Y7Ll4TlnmshN /hg7zkIuASL+Ei54eWxTp2lChG3B7X5SMF+/n+cTpujRLYQhEkvPFWXvOKb1qrdnzp7o9Dzs8ed8W pkj6ZMvxeygpQ3zpXuhJS75U585dzyTLmLqeU6afleM/PG2Vy+6Imo7QV67JqTqOGCaSYi9tedTjg hZEg/9KTmPPtorTOPZmRaR+Tjtuy2W9LvwDor/HqDt7/GY6F58V+HWD/Yd6W5sCsT6lHYC+e6k7Re i6JUKF9Elx+ABw+ivqiw==; 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 1gtBoI-0003Qj-Po; Mon, 11 Feb 2019 13:39:46 +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-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=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; }