From patchwork Mon Feb 20 12:30:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Gonzalez X-Patchwork-Id: 9582703 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E2968604A0 for ; Mon, 20 Feb 2017 12:36:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D39442886C for ; Mon, 20 Feb 2017 12:36:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C79B72886E; Mon, 20 Feb 2017 12:36:16 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 2D5A92886C for ; Mon, 20 Feb 2017 12:36:15 +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:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sqo86YBDequypf4cHSljkRRUq+rqOPBvuCtYMzwblX8=; b=IVtGbxB+dusdzU LjR/vVeBd9stS4SaRZB3gF2mxwxLzF0z4p9ih6tNIcvQfus79VFkdKgX7voO/9WodQfpWjXCo+Dyx fkJ8YZ9D7L2T1nFkrbINfuwnjW9ewt51oE8N1YpYiLkugbD9N9WB5k0CNIOUGOj7pyKYQq5yn5ffj jsLzBR0pmNTPRs03a/bVtNq1rLsbnNUjYWbi4+q5Axxf5o4W4V6j5FsPCBkRZGwAxGkg/2vQYE1sA Gx0zry0BMWaBwq57YQ60VdTliLyn6frxiNCBVg5B/lGwKVcSxYx4g2hMumbGDixAY0QcOEbh7SqX6 4mTKA8b05Ol4oBwo0dNw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cfnCQ-0007fI-1B; Mon, 20 Feb 2017 12:36:14 +0000 Received: from mail1.bemta12.messagelabs.com ([216.82.251.14]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cfn7H-0003Hv-SW; Mon, 20 Feb 2017 12:31:02 +0000 Received: from [216.82.249.212] by server-14.bemta-12.messagelabs.com id AE/72-13762-561EAA85; Mon, 20 Feb 2017 12:30:29 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrEIsWRWlGSWpSXmKPExsVy+LrFKt3Uh6s iDJ5OkLU48GIhi8WRC2uZLe59P89sMXHlZGaLTY+vsVrsblrGbnF0zz1mi8k73zA6cHgs+LWV xePJpouMHjtn3WX32LxCy2PzknqPm/MKA9iiWDPzkvIrElgzpnR+YSp4IFox4chetgbGw4Jdj JwcQgLLGCXWHhIFsYUFHCXaFrWyg9giAhYSHQ+PsnUxcnEwC8xiknj85gYbREOQxP8568GK2A RMJG7eP8cCYvMKOEtsOLKbqYuRg4NFQFXiwoUckLCoQILExT9TWCFKBCVOznwCVs4pECyx8dt fRhCbWUBfomnrHGYIW15i+1sIW0hAW+L9xsVgvRICChJTJ7cyT2Dkn4Vk1Cwk7bOQtC9gZF7F qFGcWlSWWqRraKmXVJSZnlGSm5iZo2toaKSXm1pcnJiempOYVKyXnJ+7iREY9vUMDIw7GKc0e h1ilORgUhLlvbNkVYQQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCV7RB0A5waLU9NSKtMwcYATCpC U4eJREeC+ApHmLCxJzizPTIVKnGBWlxHnXgyQEQBIZpXlwbbCov8QoKyXMy8jAwCDEU5BalJt Zgir/ilGcg1FJmLcUZApPZl4J3PRXQIuZgBbf9FgJsrgkESEl1cBobZF2L+itR5Gfl+gF3sKe I9bJu/qP+q1eu3WRf/ONgxeVVjD+WhLz5Zr/K4+r2xvXP4v4maAopizvMnWCptrp56ZK6wq+y hx+4xk040ecs6TGufXz7p54mjeZfV3k1pu/n79sDQqwkI3TkKlWn5oofskkWZvFoiVUoWrLBD GXtmdnUwPfvy1RYinOSDTUYi4qTgQAIt09KfUCAAA= X-Env-Sender: Marc_Gonzalez@sigmadesigns.com X-Msg-Ref: server-15.tower-219.messagelabs.com!1487593827!144544720!1 X-Originating-IP: [195.215.56.170] X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30054 invoked from network); 20 Feb 2017 12:30:29 -0000 Received: from 195-215-56-170-static.dk.customer.tdc.net (HELO CPH-EX1.SDESIGNS.COM) (195.215.56.170) by server-15.tower-219.messagelabs.com with AES128-SHA encrypted SMTP; 20 Feb 2017 12:30:29 -0000 Received: from [172.27.0.114] (172.27.0.114) by CPH-EX1.sdesigns.com (192.168.10.36) with Microsoft SMTP Server (TLS) id 14.3.294.0; Mon, 20 Feb 2017 13:30:25 +0100 Subject: Re: [PATCH] mtd: nand: tango: Enforce DMA direction type To: Boris Brezillon References: <1486979107-15362-1-git-send-email-boris.brezillon@free-electrons.com> From: Marc Gonzalez Message-ID: Date: Mon, 20 Feb 2017 13:30:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0 SeaMonkey/2.48 MIME-Version: 1.0 In-Reply-To: <1486979107-15362-1-git-send-email-boris.brezillon@free-electrons.com> X-Originating-IP: [172.27.0.114] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170220_043056_583010_0558771F X-CRM114-Status: GOOD ( 16.67 ) 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: Richard Weinberger , Marek Vasut , linux-mtd@lists.infradead.org, Cyrille Pitchen , Brian Norris , David Woodhouse , 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 On 13/02/2017 10:45, Boris Brezillon wrote: > do_dma() use an integer to pass the DMA data direction information and > pass the same value to dmaengine_prep_slave_sg(). > > Currently, DMA_{FROM,TO}_DEVICE match DMA_{DEV_TO_MEM,MEM_TO_DEV} > definitions so it works fine, but assuming this will always be the case > is not safe. > > Enforce enum dma_data_direction type in the function prototype and make > the enum dma_data_direction -> enum dma_transfer_direction conversion > explicit. > > Reported-by: Richard Weinberger > Signed-off-by: Boris Brezillon > --- > drivers/mtd/nand/tango_nand.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/mtd/nand/tango_nand.c b/drivers/mtd/nand/tango_nand.c > index 4a5e948c62df..9a0e2f85d865 100644 > --- a/drivers/mtd/nand/tango_nand.c > +++ b/drivers/mtd/nand/tango_nand.c > @@ -223,8 +223,8 @@ static void tango_dma_callback(void *arg) > complete(arg); > } > > -static int do_dma(struct tango_nfc *nfc, int dir, int cmd, const void *buf, > - int len, int page) > +static int do_dma(struct tango_nfc *nfc, enum dma_data_direction dir, int cmd, > + const void *buf, int len, int page) > { > void __iomem *addr = nfc->reg_base + NFC_STATUS; > struct dma_chan *chan = nfc->chan; > @@ -238,7 +238,10 @@ static int do_dma(struct tango_nfc *nfc, int dir, int cmd, const void *buf, > if (dma_map_sg(chan->device->dev, &sg, 1, dir) != 1) > return -EIO; > > - desc = dmaengine_prep_slave_sg(chan, &sg, 1, dir, DMA_PREP_INTERRUPT); > + desc = dmaengine_prep_slave_sg(chan, &sg, 1, > + dir == DMA_FROM_DEVICE ? > + DMA_DEV_TO_MEM : DMA_MEM_TO_DEV, > + DMA_PREP_INTERRUPT); > if (!desc) > goto dma_unmap; > > How about evaluating the ternary conditional into a temp var? diff --git a/drivers/mtd/nand/tango_nand.c b/drivers/mtd/nand/tango_nand.c index 4a5e948c62df..c3f145528f1d 100644 --- a/drivers/mtd/nand/tango_nand.c +++ b/drivers/mtd/nand/tango_nand.c @@ -231,6 +231,7 @@ static int do_dma(struct tango_nfc *nfc, int dir, int cmd, const void *buf, struct dma_async_tx_descriptor *desc; struct scatterlist sg; struct completion tx_done; + int xdir = dir == DMA_TO_DEVICE ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM; int err = -EIO; u32 res, val; @@ -238,7 +239,7 @@ static int do_dma(struct tango_nfc *nfc, int dir, int cmd, const void *buf, if (dma_map_sg(chan->device->dev, &sg, 1, dir) != 1) return -EIO; - desc = dmaengine_prep_slave_sg(chan, &sg, 1, dir, DMA_PREP_INTERRUPT); + desc = dmaengine_prep_slave_sg(chan, &sg, 1, xdir, DMA_PREP_INTERRUPT); if (!desc) goto dma_unmap;