All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto: marvell/cesa - Fix DMA API misuse
@ 2018-01-10 15:15 ` Robin Murphy
  0 siblings, 0 replies; 10+ messages in thread
From: Robin Murphy @ 2018-01-10 15:15 UTC (permalink / raw)
  To: boris.brezillon, arno
  Cc: herbert, davem, hch, linux-crypto, linux-arm-kernel, linux-kernel

phys_to_dma() is an internal helper for certain DMA API implementations,
and is not appropriate for drivers to use. It appears that what the CESA
driver really wants to be using is dma_map_resource() - admittedly that
didn't exist when the offending code was first merged, but it does now.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---

Found by inspection and compile-tested only

 drivers/crypto/marvell/cesa.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/marvell/cesa.c b/drivers/crypto/marvell/cesa.c
index 293832488cc9..f81fa4a3e66b 100644
--- a/drivers/crypto/marvell/cesa.c
+++ b/drivers/crypto/marvell/cesa.c
@@ -15,6 +15,7 @@
  */
 
 #include <linux/delay.h>
+#include <linux/dma-mapping.h>
 #include <linux/genalloc.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
@@ -409,8 +410,11 @@ static int mv_cesa_get_sram(struct platform_device *pdev, int idx)
 	if (IS_ERR(engine->sram))
 		return PTR_ERR(engine->sram);
 
-	engine->sram_dma = phys_to_dma(cesa->dev,
-				       (phys_addr_t)res->start);
+	engine->sram_dma = dma_map_resource(cesa->dev, res->start,
+					    cesa->sram_size,
+					    DMA_BIDIRECTIONAL, 0);
+	if (dma_mapping_error(cesa->dev, engine->sram_dma))
+		return -ENOMEM;
 
 	return 0;
 }
@@ -420,11 +424,12 @@ static void mv_cesa_put_sram(struct platform_device *pdev, int idx)
 	struct mv_cesa_dev *cesa = platform_get_drvdata(pdev);
 	struct mv_cesa_engine *engine = &cesa->engines[idx];
 
-	if (!engine->pool)
-		return;
-
-	gen_pool_free(engine->pool, (unsigned long)engine->sram,
-		      cesa->sram_size);
+	if (engine->pool)
+		gen_pool_free(engine->pool, (unsigned long)engine->sram,
+			      cesa->sram_size);
+	else
+		dma_unmap_resource(cesa->dev, engine->sram_dma,
+				   cesa->sram_size, DMA_BIDIRECTIONAL, 0);
 }
 
 static int mv_cesa_probe(struct platform_device *pdev)
-- 
2.13.4.dirty

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

* [PATCH] crypto: marvell/cesa - Fix DMA API misuse
@ 2018-01-10 15:15 ` Robin Murphy
  0 siblings, 0 replies; 10+ messages in thread
From: Robin Murphy @ 2018-01-10 15:15 UTC (permalink / raw)
  To: linux-arm-kernel

phys_to_dma() is an internal helper for certain DMA API implementations,
and is not appropriate for drivers to use. It appears that what the CESA
driver really wants to be using is dma_map_resource() - admittedly that
didn't exist when the offending code was first merged, but it does now.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---

Found by inspection and compile-tested only

 drivers/crypto/marvell/cesa.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/marvell/cesa.c b/drivers/crypto/marvell/cesa.c
index 293832488cc9..f81fa4a3e66b 100644
--- a/drivers/crypto/marvell/cesa.c
+++ b/drivers/crypto/marvell/cesa.c
@@ -15,6 +15,7 @@
  */
 
 #include <linux/delay.h>
+#include <linux/dma-mapping.h>
 #include <linux/genalloc.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
@@ -409,8 +410,11 @@ static int mv_cesa_get_sram(struct platform_device *pdev, int idx)
 	if (IS_ERR(engine->sram))
 		return PTR_ERR(engine->sram);
 
-	engine->sram_dma = phys_to_dma(cesa->dev,
-				       (phys_addr_t)res->start);
+	engine->sram_dma = dma_map_resource(cesa->dev, res->start,
+					    cesa->sram_size,
+					    DMA_BIDIRECTIONAL, 0);
+	if (dma_mapping_error(cesa->dev, engine->sram_dma))
+		return -ENOMEM;
 
 	return 0;
 }
@@ -420,11 +424,12 @@ static void mv_cesa_put_sram(struct platform_device *pdev, int idx)
 	struct mv_cesa_dev *cesa = platform_get_drvdata(pdev);
 	struct mv_cesa_engine *engine = &cesa->engines[idx];
 
-	if (!engine->pool)
-		return;
-
-	gen_pool_free(engine->pool, (unsigned long)engine->sram,
-		      cesa->sram_size);
+	if (engine->pool)
+		gen_pool_free(engine->pool, (unsigned long)engine->sram,
+			      cesa->sram_size);
+	else
+		dma_unmap_resource(cesa->dev, engine->sram_dma,
+				   cesa->sram_size, DMA_BIDIRECTIONAL, 0);
 }
 
 static int mv_cesa_probe(struct platform_device *pdev)
-- 
2.13.4.dirty

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

* Re: [PATCH] crypto: marvell/cesa - Fix DMA API misuse
  2018-01-10 15:15 ` Robin Murphy
@ 2018-01-10 15:25   ` Boris Brezillon
  -1 siblings, 0 replies; 10+ messages in thread
From: Boris Brezillon @ 2018-01-10 15:25 UTC (permalink / raw)
  To: Robin Murphy
  Cc: arno, herbert, davem, hch, linux-crypto, linux-arm-kernel, linux-kernel

On Wed, 10 Jan 2018 15:15:43 +0000
Robin Murphy <robin.murphy@arm.com> wrote:

> phys_to_dma() is an internal helper for certain DMA API implementations,
> and is not appropriate for drivers to use. It appears that what the CESA
> driver really wants to be using is dma_map_resource() - admittedly that
> didn't exist when the offending code was first merged, but it does now.
> 
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>

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

> ---
> 
> Found by inspection and compile-tested only
> 
>  drivers/crypto/marvell/cesa.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/crypto/marvell/cesa.c b/drivers/crypto/marvell/cesa.c
> index 293832488cc9..f81fa4a3e66b 100644
> --- a/drivers/crypto/marvell/cesa.c
> +++ b/drivers/crypto/marvell/cesa.c
> @@ -15,6 +15,7 @@
>   */
>  
>  #include <linux/delay.h>
> +#include <linux/dma-mapping.h>
>  #include <linux/genalloc.h>
>  #include <linux/interrupt.h>
>  #include <linux/io.h>
> @@ -409,8 +410,11 @@ static int mv_cesa_get_sram(struct platform_device *pdev, int idx)
>  	if (IS_ERR(engine->sram))
>  		return PTR_ERR(engine->sram);
>  
> -	engine->sram_dma = phys_to_dma(cesa->dev,
> -				       (phys_addr_t)res->start);
> +	engine->sram_dma = dma_map_resource(cesa->dev, res->start,
> +					    cesa->sram_size,
> +					    DMA_BIDIRECTIONAL, 0);
> +	if (dma_mapping_error(cesa->dev, engine->sram_dma))
> +		return -ENOMEM;
>  
>  	return 0;
>  }
> @@ -420,11 +424,12 @@ static void mv_cesa_put_sram(struct platform_device *pdev, int idx)
>  	struct mv_cesa_dev *cesa = platform_get_drvdata(pdev);
>  	struct mv_cesa_engine *engine = &cesa->engines[idx];
>  
> -	if (!engine->pool)
> -		return;
> -
> -	gen_pool_free(engine->pool, (unsigned long)engine->sram,
> -		      cesa->sram_size);
> +	if (engine->pool)
> +		gen_pool_free(engine->pool, (unsigned long)engine->sram,
> +			      cesa->sram_size);
> +	else
> +		dma_unmap_resource(cesa->dev, engine->sram_dma,
> +				   cesa->sram_size, DMA_BIDIRECTIONAL, 0);
>  }
>  
>  static int mv_cesa_probe(struct platform_device *pdev)

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

* [PATCH] crypto: marvell/cesa - Fix DMA API misuse
@ 2018-01-10 15:25   ` Boris Brezillon
  0 siblings, 0 replies; 10+ messages in thread
From: Boris Brezillon @ 2018-01-10 15:25 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, 10 Jan 2018 15:15:43 +0000
Robin Murphy <robin.murphy@arm.com> wrote:

> phys_to_dma() is an internal helper for certain DMA API implementations,
> and is not appropriate for drivers to use. It appears that what the CESA
> driver really wants to be using is dma_map_resource() - admittedly that
> didn't exist when the offending code was first merged, but it does now.
> 
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>

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

> ---
> 
> Found by inspection and compile-tested only
> 
>  drivers/crypto/marvell/cesa.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/crypto/marvell/cesa.c b/drivers/crypto/marvell/cesa.c
> index 293832488cc9..f81fa4a3e66b 100644
> --- a/drivers/crypto/marvell/cesa.c
> +++ b/drivers/crypto/marvell/cesa.c
> @@ -15,6 +15,7 @@
>   */
>  
>  #include <linux/delay.h>
> +#include <linux/dma-mapping.h>
>  #include <linux/genalloc.h>
>  #include <linux/interrupt.h>
>  #include <linux/io.h>
> @@ -409,8 +410,11 @@ static int mv_cesa_get_sram(struct platform_device *pdev, int idx)
>  	if (IS_ERR(engine->sram))
>  		return PTR_ERR(engine->sram);
>  
> -	engine->sram_dma = phys_to_dma(cesa->dev,
> -				       (phys_addr_t)res->start);
> +	engine->sram_dma = dma_map_resource(cesa->dev, res->start,
> +					    cesa->sram_size,
> +					    DMA_BIDIRECTIONAL, 0);
> +	if (dma_mapping_error(cesa->dev, engine->sram_dma))
> +		return -ENOMEM;
>  
>  	return 0;
>  }
> @@ -420,11 +424,12 @@ static void mv_cesa_put_sram(struct platform_device *pdev, int idx)
>  	struct mv_cesa_dev *cesa = platform_get_drvdata(pdev);
>  	struct mv_cesa_engine *engine = &cesa->engines[idx];
>  
> -	if (!engine->pool)
> -		return;
> -
> -	gen_pool_free(engine->pool, (unsigned long)engine->sram,
> -		      cesa->sram_size);
> +	if (engine->pool)
> +		gen_pool_free(engine->pool, (unsigned long)engine->sram,
> +			      cesa->sram_size);
> +	else
> +		dma_unmap_resource(cesa->dev, engine->sram_dma,
> +				   cesa->sram_size, DMA_BIDIRECTIONAL, 0);
>  }
>  
>  static int mv_cesa_probe(struct platform_device *pdev)

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

* Re: [PATCH] crypto: marvell/cesa - Fix DMA API misuse
  2018-01-10 15:25   ` Boris Brezillon
@ 2018-01-10 15:48     ` Christoph Hellwig
  -1 siblings, 0 replies; 10+ messages in thread
From: Christoph Hellwig @ 2018-01-10 15:48 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Robin Murphy, arno, herbert, davem, hch, linux-crypto,
	linux-arm-kernel, linux-kernel

On Wed, Jan 10, 2018 at 04:25:22PM +0100, Boris Brezillon wrote:
> On Wed, 10 Jan 2018 15:15:43 +0000
> Robin Murphy <robin.murphy@arm.com> wrote:
> 
> > phys_to_dma() is an internal helper for certain DMA API implementations,
> > and is not appropriate for drivers to use. It appears that what the CESA
> > driver really wants to be using is dma_map_resource() - admittedly that
> > didn't exist when the offending code was first merged, but it does now.
> > 
> > Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> 
> Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>

Thanks.  Robin, Boris: do you want me to pick this up in the
dma-mapping tree and move it before the dma-direct.h introduction?

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

* [PATCH] crypto: marvell/cesa - Fix DMA API misuse
@ 2018-01-10 15:48     ` Christoph Hellwig
  0 siblings, 0 replies; 10+ messages in thread
From: Christoph Hellwig @ 2018-01-10 15:48 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Jan 10, 2018 at 04:25:22PM +0100, Boris Brezillon wrote:
> On Wed, 10 Jan 2018 15:15:43 +0000
> Robin Murphy <robin.murphy@arm.com> wrote:
> 
> > phys_to_dma() is an internal helper for certain DMA API implementations,
> > and is not appropriate for drivers to use. It appears that what the CESA
> > driver really wants to be using is dma_map_resource() - admittedly that
> > didn't exist when the offending code was first merged, but it does now.
> > 
> > Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> 
> Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>

Thanks.  Robin, Boris: do you want me to pick this up in the
dma-mapping tree and move it before the dma-direct.h introduction?

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

* Re: [PATCH] crypto: marvell/cesa - Fix DMA API misuse
  2018-01-10 15:48     ` Christoph Hellwig
@ 2018-01-10 16:23       ` Boris Brezillon
  -1 siblings, 0 replies; 10+ messages in thread
From: Boris Brezillon @ 2018-01-10 16:23 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Robin Murphy, arno, herbert, davem, linux-crypto,
	linux-arm-kernel, linux-kernel

Hi Christoph,

On Wed, 10 Jan 2018 16:48:17 +0100
Christoph Hellwig <hch@lst.de> wrote:

> On Wed, Jan 10, 2018 at 04:25:22PM +0100, Boris Brezillon wrote:
> > On Wed, 10 Jan 2018 15:15:43 +0000
> > Robin Murphy <robin.murphy@arm.com> wrote:
> >   
> > > phys_to_dma() is an internal helper for certain DMA API implementations,
> > > and is not appropriate for drivers to use. It appears that what the CESA
> > > driver really wants to be using is dma_map_resource() - admittedly that
> > > didn't exist when the offending code was first merged, but it does now.
> > > 
> > > Signed-off-by: Robin Murphy <robin.murphy@arm.com>  
> > 
> > Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>  
> 
> Thanks.  Robin, Boris: do you want me to pick this up in the
> dma-mapping tree and move it before the dma-direct.h introduction?

You should probably sync with Herbert, I'm just the maintainer of this
driver, not the crypto subsystem.

Regards,

Boris

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

* [PATCH] crypto: marvell/cesa - Fix DMA API misuse
@ 2018-01-10 16:23       ` Boris Brezillon
  0 siblings, 0 replies; 10+ messages in thread
From: Boris Brezillon @ 2018-01-10 16:23 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Christoph,

On Wed, 10 Jan 2018 16:48:17 +0100
Christoph Hellwig <hch@lst.de> wrote:

> On Wed, Jan 10, 2018 at 04:25:22PM +0100, Boris Brezillon wrote:
> > On Wed, 10 Jan 2018 15:15:43 +0000
> > Robin Murphy <robin.murphy@arm.com> wrote:
> >   
> > > phys_to_dma() is an internal helper for certain DMA API implementations,
> > > and is not appropriate for drivers to use. It appears that what the CESA
> > > driver really wants to be using is dma_map_resource() - admittedly that
> > > didn't exist when the offending code was first merged, but it does now.
> > > 
> > > Signed-off-by: Robin Murphy <robin.murphy@arm.com>  
> > 
> > Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>  
> 
> Thanks.  Robin, Boris: do you want me to pick this up in the
> dma-mapping tree and move it before the dma-direct.h introduction?

You should probably sync with Herbert, I'm just the maintainer of this
driver, not the crypto subsystem.

Regards,

Boris

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

* Re: [PATCH] crypto: marvell/cesa - Fix DMA API misuse
  2018-01-10 15:15 ` Robin Murphy
@ 2018-01-18 12:03   ` Herbert Xu
  -1 siblings, 0 replies; 10+ messages in thread
From: Herbert Xu @ 2018-01-18 12:03 UTC (permalink / raw)
  To: Robin Murphy
  Cc: boris.brezillon, arno, davem, hch, linux-crypto,
	linux-arm-kernel, linux-kernel

On Wed, Jan 10, 2018 at 03:15:43PM +0000, Robin Murphy wrote:
> phys_to_dma() is an internal helper for certain DMA API implementations,
> and is not appropriate for drivers to use. It appears that what the CESA
> driver really wants to be using is dma_map_resource() - admittedly that
> didn't exist when the offending code was first merged, but it does now.
> 
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* [PATCH] crypto: marvell/cesa - Fix DMA API misuse
@ 2018-01-18 12:03   ` Herbert Xu
  0 siblings, 0 replies; 10+ messages in thread
From: Herbert Xu @ 2018-01-18 12:03 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Jan 10, 2018 at 03:15:43PM +0000, Robin Murphy wrote:
> phys_to_dma() is an internal helper for certain DMA API implementations,
> and is not appropriate for drivers to use. It appears that what the CESA
> driver really wants to be using is dma_map_resource() - admittedly that
> didn't exist when the offending code was first merged, but it does now.
> 
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2018-01-18 12:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-10 15:15 [PATCH] crypto: marvell/cesa - Fix DMA API misuse Robin Murphy
2018-01-10 15:15 ` Robin Murphy
2018-01-10 15:25 ` Boris Brezillon
2018-01-10 15:25   ` Boris Brezillon
2018-01-10 15:48   ` Christoph Hellwig
2018-01-10 15:48     ` Christoph Hellwig
2018-01-10 16:23     ` Boris Brezillon
2018-01-10 16:23       ` Boris Brezillon
2018-01-18 12:03 ` Herbert Xu
2018-01-18 12:03   ` Herbert Xu

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.