From patchwork Mon Jan 4 21:36:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Nazarewicz?= X-Patchwork-Id: 7951371 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9614FBEEE5 for ; Mon, 4 Jan 2016 21:39:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B2ED620320 for ; Mon, 4 Jan 2016 21:39:16 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C1B6C20303 for ; Mon, 4 Jan 2016 21:39:15 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aGCoa-0004J9-2p; Mon, 04 Jan 2016 21:37:20 +0000 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aGCoV-0004Ga-V3 for linux-arm-kernel@lists.infradead.org; Mon, 04 Jan 2016 21:37:17 +0000 Received: by mail-wm0-x22c.google.com with SMTP id f206so1502977wmf.0 for ; Mon, 04 Jan 2016 13:36:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=htWM4kcaodSBCMUskYAqIZq5A8YYegP7mj/6McRaj4U=; b=ZYk7fPzxVz96J4JNe5HZ+q3fnu/AsjCgefqge/QtncSHGR1WBKM6iYgaN0B4Ye51rx eqS5s/T7cuYcFZOCyQdxVnayYEWin3bd0V9gfKO3QGbqJdEwydxsFJbpaRAq+f50IRjH wag5gRp3jPkaOqcFMd3ACz0XEKxB2Wcy3oK7K2Bh6g1d6VaAFPbZTPS9OovUtqKMDta+ MjjiZTRzz9mduut0oQRu9unIXo3W4CwEHgpy/vX74sTGqrYLsMu0Bis1IInlHQ7Spp2y fQMdF8N4KiStC5ANcUGdbZ9rcblPxKGKNEkmzoKsGbGou7RUxs3fBPiJ5Y2eeNMYy/ba Xxiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=htWM4kcaodSBCMUskYAqIZq5A8YYegP7mj/6McRaj4U=; b=YieZ9WJj9z2pvaZjNAWFg3nCbICHogUcQ2R3rMLDjSe5+TkKQXQzbb4K3PeGMfYF2f FXPb4g4hlIIyZgZWmPa28lUbB+Lkc3du6JzMr7Hvq4ZvZqMkglUBp8jsg8ZcL8TEDKio NeuJ1J6wJIstqwHM2bKOdDmy7lhkaHLhybbq4HvTPaxbGnIkI1oS1Heshz6Sgyi7W7kM t74Y7BjwmMslrzKzYnr7Bwdj1KBqi22quOZZ8IkXBN7g8h/fwqE2odt+7VNgUv0TCwVQ xPNTZ6VXBHgpPRivlyQhyQpoI2uxOJSp0h4ZcT2BWFyGPdJh/sTMWo1mnUn7FTFobsdy gcFA== X-Gm-Message-State: ALoCoQmXWd151QtYdQO3v8+H4Cgm2YNbmJWbKIhwfSJ8chNPbEE+/EbCvVTxGrerj297wVBHvlJmGVwYTAC62Vq32Kqww7D+8A== X-Received: by 10.194.243.103 with SMTP id wx7mr106991486wjc.136.1451943413798; Mon, 04 Jan 2016 13:36:53 -0800 (PST) Received: from mpn.zrh.corp.google.com ([2620:0:105f:302:3c21:a96f:dbe0:1961]) by smtp.gmail.com with ESMTPSA id w73sm440209wmw.21.2016.01.04.13.36.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jan 2016 13:36:51 -0800 (PST) Received: by mpn.zrh.corp.google.com (Postfix, from userid 126942) id BA6F21E0266; Mon, 4 Jan 2016 22:36:50 +0100 (CET) From: Michal Nazarewicz To: Greg Kroah-Hartman Subject: [PATCHv2] drivers: dma-coherent: simplify dma_init_coherent_memory return value Date: Mon, 4 Jan 2016 22:36:40 +0100 Message-Id: <1451943400-17190-1-git-send-email-mina86@mina86.com> X-Mailer: git-send-email 2.6.0.rc2.230.g3dd15c0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160104_133716_148755_791A6941 X-CRM114-Status: GOOD ( 15.21 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Nazarewicz , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Marek Szyprowski MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since only dma_declare_coherent_memory cares about dma_init_coherent_memory returning part of flags as it return value, move the condition to the former and simplify the latter. This in turn makes rmem_dma_device_init less confusing. Reported-by: Fugang Duan Signed-off-by: Michal Nazarewicz Acked-by: Marek Szyprowski --- drivers/base/dma-coherent.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c index 55b8398..87b8083 100644 --- a/drivers/base/dma-coherent.c +++ b/drivers/base/dma-coherent.c @@ -17,9 +17,9 @@ struct dma_coherent_mem { spinlock_t spinlock; }; -static int dma_init_coherent_memory(phys_addr_t phys_addr, dma_addr_t device_addr, - size_t size, int flags, - struct dma_coherent_mem **mem) +static bool dma_init_coherent_memory( + phys_addr_t phys_addr, dma_addr_t device_addr, size_t size, int flags, + struct dma_coherent_mem **mem) { struct dma_coherent_mem *dma_mem = NULL; void __iomem *mem_base = NULL; @@ -50,17 +50,13 @@ static int dma_init_coherent_memory(phys_addr_t phys_addr, dma_addr_t device_add spin_lock_init(&dma_mem->spinlock); *mem = dma_mem; - - if (flags & DMA_MEMORY_MAP) - return DMA_MEMORY_MAP; - - return DMA_MEMORY_IO; + return true; out: kfree(dma_mem); if (mem_base) iounmap(mem_base); - return 0; + return false; } static void dma_release_coherent_memory(struct dma_coherent_mem *mem) @@ -88,15 +84,13 @@ int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, dma_addr_t device_addr, size_t size, int flags) { struct dma_coherent_mem *mem; - int ret; - ret = dma_init_coherent_memory(phys_addr, device_addr, size, flags, - &mem); - if (ret == 0) + if (!dma_init_coherent_memory(phys_addr, device_addr, size, flags, + &mem)) return 0; if (dma_assign_coherent_memory(dev, mem) == 0) - return ret; + return flags & DMA_MEMORY_MAP ? DMA_MEMORY_MAP : DMA_MEMORY_IO; dma_release_coherent_memory(mem); return 0; @@ -281,9 +275,9 @@ static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev) struct dma_coherent_mem *mem = rmem->priv; if (!mem && - dma_init_coherent_memory(rmem->base, rmem->base, rmem->size, - DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE, - &mem) != DMA_MEMORY_MAP) { + !dma_init_coherent_memory(rmem->base, rmem->base, rmem->size, + DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE, + &mem)) { 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 -ENODEV;