crypto: cesa: check for sram_dma NULL
Subsystems (2)
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()
--- drivers/crypto/marvell/cesa/cesa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/marvell/cesa/cesa.c +1 -1
@@ -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
Quoted 2 lines · Rosen Penev
dma_map_resource()might fail. In such a case, don't calldma_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")Signed-off-by Rosen Penev <[email protected]>--- drivers/crypto/marvell/cesa/cesa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/crypto/marvell/cesa/cesa.c +1
-1@@ -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 ); }
Quoted 5 lines · Robin Murphy
Quoted 2 lines · Rosen Penev
dma_map_resource()might fail. In such a case, don't calldma_unmap_resource()
Quoted 9 lines
Hmm, AFAICS it's more that if *anything* in
mv_cesa_get_sram()fails, we could end up callingdma_unmap_resource()via the cleanup path for subsequent engines which never had theirmv_cesa_get_sram()call at all (and thus all ofengine->pool,engine->sramandengine->sram_dmawill be unset). While for one wheredma_map_resource()itself did fail,engine->sram_dmawill 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")Signed-off-by Rosen Penev <[email protected]>--- drivers/crypto/marvell/cesa/cesa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/crypto/marvell/cesa/cesa.c +1
-1@@ -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 ); }