mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: cesa: check for sram_dma NULL
@ 2026-07-13  5:07 Rosen Penev
  2026-07-13 11:58 ` Robin Murphy
  0 siblings, 1 reply; 3+ messages in thread
From: Rosen Penev @ 2026-07-13  5:07 UTC (permalink / raw)
  To: linux-crypto
  Cc: Srujana Challa, Bharat Bhushan, Herbert Xu, David S. Miller,
	Boris Brezillon, Robin Murphy, open list

dma_map_resource() might fail. In such a case, don't call
dma_unmap_resource()

Fixes: 37d728f76c41 ("crypto: marvell/cesa - Fix DMA API misuse")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/crypto/marvell/cesa/cesa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/marvell/cesa/cesa.c b/drivers/crypto/marvell/cesa/cesa.c
index 57c9295be711..bcbb909c48d8 100644
--- a/drivers/crypto/marvell/cesa/cesa.c
+++ b/drivers/crypto/marvell/cesa/cesa.c
@@ -406,7 +406,7 @@ static void mv_cesa_put_sram(struct platform_device *pdev, int idx)
 	if (engine->pool)
 		gen_pool_free(engine->pool, (unsigned long)engine->sram_pool,
 			      cesa->sram_size);
-	else
+	else if (engine->sram_dma)
 		dma_unmap_resource(cesa->dev, engine->sram_dma,
 				   cesa->sram_size, DMA_BIDIRECTIONAL, 0);
 }
-- 
2.55.0


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

* Re: [PATCH] crypto: cesa: check for sram_dma NULL
  2026-07-13  5:07 [PATCH] crypto: cesa: check for sram_dma NULL Rosen Penev
@ 2026-07-13 11:58 ` Robin Murphy
  2026-07-13 19:50   ` Rosen Penev
  0 siblings, 1 reply; 3+ messages in thread
From: Robin Murphy @ 2026-07-13 11:58 UTC (permalink / raw)
  To: Rosen Penev, linux-crypto
  Cc: Srujana Challa, Bharat Bhushan, Herbert Xu, David S. Miller,
	Boris Brezillon, open list

On 13/07/2026 6:07 am, Rosen Penev wrote:
> dma_map_resource() might fail. In such a case, don't call
> dma_unmap_resource()

Hmm, AFAICS it's more that if *anything* in mv_cesa_get_sram() fails, we 
could end up calling dma_unmap_resource() via the cleanup path for 
subsequent engines which never had their mv_cesa_get_sram() call at all 
(and thus all of engine->pool, engine->sram and engine->sram_dma will be 
unset). While for one where dma_map_resource() itself did fail, 
engine->sram_dma will be non-NULL here (but still invalid to unmap). I 
think this needs a bit more work to differentiate between the 
successfully initialised state which needs cleanup, and the partially or 
fully-uninitialised states which don't.

Thanks,
Robin.

> Fixes: 37d728f76c41 ("crypto: marvell/cesa - Fix DMA API misuse")
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>   drivers/crypto/marvell/cesa/cesa.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/crypto/marvell/cesa/cesa.c b/drivers/crypto/marvell/cesa/cesa.c
> index 57c9295be711..bcbb909c48d8 100644
> --- a/drivers/crypto/marvell/cesa/cesa.c
> +++ b/drivers/crypto/marvell/cesa/cesa.c
> @@ -406,7 +406,7 @@ static void mv_cesa_put_sram(struct platform_device *pdev, int idx)
>   	if (engine->pool)
>   		gen_pool_free(engine->pool, (unsigned long)engine->sram_pool,
>   			      cesa->sram_size);
> -	else
> +	else if (engine->sram_dma)
>   		dma_unmap_resource(cesa->dev, engine->sram_dma,
>   				   cesa->sram_size, DMA_BIDIRECTIONAL, 0);
>   }


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

* Re: [PATCH] crypto: cesa: check for sram_dma NULL
  2026-07-13 11:58 ` Robin Murphy
@ 2026-07-13 19:50   ` Rosen Penev
  0 siblings, 0 replies; 3+ messages in thread
From: Rosen Penev @ 2026-07-13 19:50 UTC (permalink / raw)
  To: Robin Murphy
  Cc: linux-crypto, Srujana Challa, Bharat Bhushan, Herbert Xu,
	David S. Miller, Boris Brezillon, open list

On Mon, Jul 13, 2026 at 4:58 AM Robin Murphy <robin.murphy@arm.com> wrote:
>
> On 13/07/2026 6:07 am, Rosen Penev wrote:
> > dma_map_resource() might fail. In such a case, don't call
> > dma_unmap_resource()
>
> Hmm, AFAICS it's more that if *anything* in mv_cesa_get_sram() fails, we
> could end up calling dma_unmap_resource() via the cleanup path for
> subsequent engines which never had their mv_cesa_get_sram() call at all
> (and thus all of engine->pool, engine->sram and engine->sram_dma will be
> unset). While for one where dma_map_resource() itself did fail,
> engine->sram_dma will be non-NULL here (but still invalid to unmap). I
> think this needs a bit more work to differentiate between the
> successfully initialised state which needs cleanup, and the partially or
> fully-uninitialised states which don't.
Sounds like this should have an extra check for dma_mapping_error then.
>
> Thanks,
> Robin.
>
> > Fixes: 37d728f76c41 ("crypto: marvell/cesa - Fix DMA API misuse")
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > ---
> >   drivers/crypto/marvell/cesa/cesa.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/crypto/marvell/cesa/cesa.c b/drivers/crypto/marvell/cesa/cesa.c
> > index 57c9295be711..bcbb909c48d8 100644
> > --- a/drivers/crypto/marvell/cesa/cesa.c
> > +++ b/drivers/crypto/marvell/cesa/cesa.c
> > @@ -406,7 +406,7 @@ static void mv_cesa_put_sram(struct platform_device *pdev, int idx)
> >       if (engine->pool)
> >               gen_pool_free(engine->pool, (unsigned long)engine->sram_pool,
> >                             cesa->sram_size);
> > -     else
> > +     else if (engine->sram_dma)
> >               dma_unmap_resource(cesa->dev, engine->sram_dma,
> >                                  cesa->sram_size, DMA_BIDIRECTIONAL, 0);
> >   }
>

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

end of thread, other threads:[~2026-07-13 19:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-13  5:07 [PATCH] crypto: cesa: check for sram_dma NULL Rosen Penev
2026-07-13 11:58 ` Robin Murphy
2026-07-13 19:50   ` Rosen Penev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox