All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: nand: tango: Enforce DMA direction type
@ 2017-02-13  9:45 ` Boris Brezillon
  0 siblings, 0 replies; 12+ messages in thread
From: Boris Brezillon @ 2017-02-13  9:45 UTC (permalink / raw)
  To: Marc Gonzalez
  Cc: Boris Brezillon, Richard Weinberger, linux-mtd, David Woodhouse,
	Brian Norris, Marek Vasut, Cyrille Pitchen, linux-arm-kernel

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 <richard@nod.at>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 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;
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH] mtd: nand: tango: Enforce DMA direction type
@ 2017-02-13  9:45 ` Boris Brezillon
  0 siblings, 0 replies; 12+ messages in thread
From: Boris Brezillon @ 2017-02-13  9:45 UTC (permalink / raw)
  To: linux-arm-kernel

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 <richard@nod.at>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 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;
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] mtd: nand: tango: Enforce DMA direction type
  2017-02-13  9:45 ` Boris Brezillon
@ 2017-02-13 10:54   ` Richard Weinberger
  -1 siblings, 0 replies; 12+ messages in thread
From: Richard Weinberger @ 2017-02-13 10:54 UTC (permalink / raw)
  To: Boris Brezillon, Marc Gonzalez
  Cc: linux-mtd, David Woodhouse, Brian Norris, Marek Vasut,
	Cyrille Pitchen, linux-arm-kernel

Am 13.02.2017 um 10:45 schrieb Boris Brezillon:
> 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 <richard@nod.at>
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
>  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;
>  

Reviewed-by: Richard Weinberger <richard@nod.at>

Thanks,
//richard

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] mtd: nand: tango: Enforce DMA direction type
@ 2017-02-13 10:54   ` Richard Weinberger
  0 siblings, 0 replies; 12+ messages in thread
From: Richard Weinberger @ 2017-02-13 10:54 UTC (permalink / raw)
  To: linux-arm-kernel

Am 13.02.2017 um 10:45 schrieb Boris Brezillon:
> 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 <richard@nod.at>
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
>  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;
>  

Reviewed-by: Richard Weinberger <richard@nod.at>

Thanks,
//richard

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mtd: nand: tango: Enforce DMA direction type
  2017-02-13  9:45 ` Boris Brezillon
@ 2017-02-20 12:30   ` Marc Gonzalez
  -1 siblings, 0 replies; 12+ messages in thread
From: Marc Gonzalez @ 2017-02-20 12:30 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Richard Weinberger, linux-mtd, David Woodhouse, Brian Norris,
	Marek Vasut, Cyrille Pitchen, linux-arm-kernel

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 <richard@nod.at>
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
>  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;
 

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH] mtd: nand: tango: Enforce DMA direction type
@ 2017-02-20 12:30   ` Marc Gonzalez
  0 siblings, 0 replies; 12+ messages in thread
From: Marc Gonzalez @ 2017-02-20 12:30 UTC (permalink / raw)
  To: linux-arm-kernel

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 <richard@nod.at>
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
>  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;
 

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] mtd: nand: tango: Enforce DMA direction type
  2017-02-20 12:30   ` Marc Gonzalez
@ 2017-02-20 12:35     ` Boris Brezillon
  -1 siblings, 0 replies; 12+ messages in thread
From: Boris Brezillon @ 2017-02-20 12:35 UTC (permalink / raw)
  To: Marc Gonzalez
  Cc: Richard Weinberger, linux-mtd, David Woodhouse, Brian Norris,
	Marek Vasut, Cyrille Pitchen, linux-arm-kernel

On Mon, 20 Feb 2017 13:30:25 +0100
Marc Gonzalez <marc_gonzalez@sigmadesigns.com> wrote:

> 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 <richard@nod.at>
> > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> > ---
> >  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?

Works for me.

> 
> 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;
>  

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] mtd: nand: tango: Enforce DMA direction type
@ 2017-02-20 12:35     ` Boris Brezillon
  0 siblings, 0 replies; 12+ messages in thread
From: Boris Brezillon @ 2017-02-20 12:35 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 20 Feb 2017 13:30:25 +0100
Marc Gonzalez <marc_gonzalez@sigmadesigns.com> wrote:

> 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 <richard@nod.at>
> > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> > ---
> >  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?

Works for me.

> 
> 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;
>  

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2] mtd: nand: tango: Enforce DMA direction type
  2017-02-20 12:35     ` Boris Brezillon
@ 2017-02-20 13:10       ` Marc Gonzalez
  -1 siblings, 0 replies; 12+ messages in thread
From: Marc Gonzalez @ 2017-02-20 13:10 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Richard Weinberger, linux-mtd, David Woodhouse, Brian Norris,
	Marek Vasut, Cyrille Pitchen, linux-arm-kernel

From: Boris Brezillon <boris.brezillon@free-electrons.com>

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@nod.at>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Marc Gonzalez <marc_gonzalez@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 4a5e948c62df..05b6e1065203 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;
 
-- 
3.14159265358979

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2] mtd: nand: tango: Enforce DMA direction type
@ 2017-02-20 13:10       ` Marc Gonzalez
  0 siblings, 0 replies; 12+ messages in thread
From: Marc Gonzalez @ 2017-02-20 13:10 UTC (permalink / raw)
  To: linux-arm-kernel

From: Boris Brezillon <boris.brezillon@free-electrons.com>

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@nod.at>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Marc Gonzalez <marc_gonzalez@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 4a5e948c62df..05b6e1065203 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;
 
-- 
3.14159265358979

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] mtd: nand: tango: Enforce DMA direction type
  2017-02-20 13:10       ` Marc Gonzalez
@ 2017-03-16  9:27         ` Boris Brezillon
  -1 siblings, 0 replies; 12+ messages in thread
From: Boris Brezillon @ 2017-03-16  9:27 UTC (permalink / raw)
  To: Marc Gonzalez
  Cc: Richard Weinberger, linux-mtd, David Woodhouse, Brian Norris,
	Marek Vasut, Cyrille Pitchen, linux-arm-kernel

On Mon, 20 Feb 2017 14:10:07 +0100
Marc Gonzalez <marc_gonzalez@sigmadesigns.com> wrote:

> From: Boris Brezillon <boris.brezillon@free-electrons.com>
> 
> 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@nod.at>
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> Acked-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>

Applied.

> ---
>  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 4a5e948c62df..05b6e1065203 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;
>  

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2] mtd: nand: tango: Enforce DMA direction type
@ 2017-03-16  9:27         ` Boris Brezillon
  0 siblings, 0 replies; 12+ messages in thread
From: Boris Brezillon @ 2017-03-16  9:27 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 20 Feb 2017 14:10:07 +0100
Marc Gonzalez <marc_gonzalez@sigmadesigns.com> wrote:

> From: Boris Brezillon <boris.brezillon@free-electrons.com>
> 
> 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@nod.at>
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> Acked-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>

Applied.

> ---
>  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 4a5e948c62df..05b6e1065203 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;
>  

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-03-16  9:27 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-13  9:45 [PATCH] mtd: nand: tango: Enforce DMA direction type Boris Brezillon
2017-02-13  9:45 ` Boris Brezillon
2017-02-13 10:54 ` Richard Weinberger
2017-02-13 10:54   ` Richard Weinberger
2017-02-20 12:30 ` Marc Gonzalez
2017-02-20 12:30   ` Marc Gonzalez
2017-02-20 12:35   ` Boris Brezillon
2017-02-20 12:35     ` Boris Brezillon
2017-02-20 13:10     ` [PATCH v2] " Marc Gonzalez
2017-02-20 13:10       ` Marc Gonzalez
2017-03-16  9:27       ` Boris Brezillon
2017-03-16  9:27         ` Boris Brezillon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.