mtd: nand: tango: Enforce DMA direction type
Subsystems (2)
PATCH 1/1 mtd: nand: tango: Enforce DMA direction type
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.
--- drivers/mtd/nand/tango_nand.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/mtd/nand/tango_nand.c +6 -3
@@ -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;
Signature · 1 line
2.7.4
Richard Weinberger
maintainerPATCH 1/1 mtd: nand: tango: Enforce DMA direction type
Am 13.02.2017 um 10:45 schrieb Boris Brezillon:
Quoted 34 lines
do_dma()use an integer to pass the DMA data direction information and pass the same value todmaengine_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_directiontype in the function prototype and make the enumdma_data_direction-> enumdma_transfer_directionconversion explicit.Reported-by Richard Weinberger <[email protected]>Signed-off-by Boris Brezillon <[email protected]>--- drivers/mtd/nand/tango_nand.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/mtd/nand/tango_nand.c +2
-2@@ -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 )
drivers/mtd/nand/tango_nand.c static int do_dma(struct tango_nfc *nfc, int dir, int cmd, const void *buf, · line 247
Quoted 10 lines
drivers/mtd/nand/tango_nand.c +4
-1return -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;
Thanks,
//richard
PATCH 1/1 mtd: nand: tango: Enforce DMA direction type
In reply to Boris BrezillonQuoted 35 lines · Boris Brezillon
do_dma()use an integer to pass the DMA data direction information and pass the same value todmaengine_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_directiontype in the function prototype and make the enumdma_data_direction-> enumdma_transfer_directionconversion explicit.Reported-by Richard Weinberger <[email protected]>Signed-off-by Boris Brezillon <[email protected]>--- drivers/mtd/nand/tango_nand.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/mtd/nand/tango_nand.c +2
-2@@ -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 )
drivers/mtd/nand/tango_nand.c static int do_dma(struct tango_nfc *nfc, int dir, int cmd, const void *buf, · line 247
Quoted 10 lines
drivers/mtd/nand/tango_nand.c +4
-1return -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?
drivers/mtd/nand/tango_nand.c +2 -1
@@ -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;
PATCH 1/1 mtd: nand: tango: Enforce DMA direction type
Quoted 38 lines · On Mon, 20 Feb 2017 13:30:25 +0100 Marc Gonzalez…
Quoted 36 lines · Boris Brezillon
do_dma()use an integer to pass the DMA data direction information and pass the same value todmaengine_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_directiontype in the function prototype and make the enumdma_data_direction-> enumdma_transfer_directionconversion explicit.Reported-by Richard Weinberger <[email protected]>Signed-off-by Boris Brezillon <[email protected]>--- drivers/mtd/nand/tango_nand.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/mtd/nand/tango_nand.c +2
-2@@ -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 ;
Quoted 11 lines
drivers/mtd/nand/tango_nand.c static int do_dma(struct tango_nfc *nfc, int dir, int cmd, const void *buf, · line 245
Quoted 9 lines
drivers/mtd/nand/tango_nand.c +4
-1- 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?
Works for me.
Quoted 22 lines
drivers/mtd/nand/tango_nand.c +2
-1@@ -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;
PATCH v2 1/1 mtd: nand: tango: Enforce DMA direction type
From: Boris Brezillon <[email protected]>
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.
--- drivers/mtd/nand/tango_nand.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/mtd/nand/tango_nand.c +5 -3
@@ -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;
Signature · 1 line
3.14159265358979
Boris Brezillon
AppliedPATCH v2 1/1 mtd: nand: tango: Enforce DMA direction type
Quoted 9 lines · On Mon, 20 Feb 2017 14:10:07 +0100 Marc Gonzalez…
From: Boris Brezillon <[email protected]>
do_dma()uses an int to pass the DMA data direction information and pass the same value todmaengine_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.
Quoted 7 lines
Enforce enum
dma_data_directiontype in the function prototype and make the enumdma_data_direction-> enumdma_transfer_directionconversion explicit.Reported-by Richard Weinberger <[email protected]>Signed-off-by Boris Brezillon <[email protected]>Acked-by Marc Gonzalez <[email protected]>
Applied.
Quoted 34 lines
--- drivers/mtd/nand/tango_nand.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/mtd/nand/tango_nand.c +5
-3@@ -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;