mtd: nand: tango: Enforce DMA direction type

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Wed May 10 19:59:06 PDT 2017


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=1932a9646b777c448aec9d992995b0bb0648b11d
Commit:     1932a9646b777c448aec9d992995b0bb0648b11d
Parent:     215157fb5338129b4b9f2dca23826084e71bcf4d
Author:     Boris Brezillon <boris.brezillon at free-electrons.com>
AuthorDate: Mon Feb 20 14:10:07 2017 +0100
Committer:  Boris Brezillon <boris.brezillon at free-electrons.com>
CommitDate: Thu Mar 16 10:26:23 2017 +0100

    mtd: nand: tango: Enforce DMA direction type
    
    do_dma() uses an int 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 <richard at nod.at>
    Signed-off-by: Boris Brezillon <boris.brezillon at free-electrons.com>
    Acked-by: Marc Gonzalez <marc_gonzalez at sigmadesigns.com>
---
 drivers/mtd/nand/tango_nand.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/tango_nand.c b/drivers/mtd/nand/tango_nand.c
index 4a5e948..05b6e10 100644
--- a/drivers/mtd/nand/tango_nand.c
+++ b/drivers/mtd/nand/tango_nand.c
@@ -223,12 +223,13 @@ 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;
 	struct dma_async_tx_descriptor *desc;
+	enum dma_transfer_direction tdir;
 	struct scatterlist sg;
 	struct completion tx_done;
 	int err = -EIO;
@@ -238,7 +239,8 @@ 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);
+	tdir = dir == DMA_TO_DEVICE ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM;
+	desc = dmaengine_prep_slave_sg(chan, &sg, 1, tdir, DMA_PREP_INTERRUPT);
 	if (!desc)
 		goto dma_unmap;
 



More information about the linux-mtd-cvs mailing list