Skip to contentSkip to conversation

crypto: cesa: check for sram_dma NULL

PATCH Superseded Rosen Penev 2 participants 3 messages Jul 13

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: cesa: check for sram_dma NULL

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

Fixes 37d728f76c41 ("crypto: marvell/cesa - Fix DMA API misuse")
---
 drivers/crypto/marvell/cesa/cesa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/marvell/cesa/cesa.c +1 -1
index 57c9295be711..bcbb909c48d8 100644
@@ -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);
 }
Signature · 1 line
2.55.0
#1 lore raw
Quoted 2 lines · Rosen Penev

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.

Quoted 19 lines
Fixes 37d728f76c41 ("crypto: marvell/cesa - Fix DMA API misuse")
---
  drivers/crypto/marvell/cesa/cesa.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/marvell/cesa/cesa.c +1 -1
index 57c9295be711..bcbb909c48d8 100644
@@ -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 lore raw
Quoted 5 lines · Robin Murphy
Quoted 2 lines · Rosen Penev

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

Quoted 9 lines

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.

Quoted 24 lines

Thanks,
Robin.

Quoted 19 lines
Fixes 37d728f76c41 ("crypto: marvell/cesa - Fix DMA API misuse")
---
  drivers/crypto/marvell/cesa/cesa.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/marvell/cesa/cesa.c +1 -1
index 57c9295be711..bcbb909c48d8 100644
@@ -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);
  }