Re: [PATCH] crypto: cesa: manage SRAM teardown with devm

From: Herbert Xu

Date: Thu Jul 30 2026 - 03:46:59 EST


On Fri, Jul 17, 2026 at 04:17:42PM -0700, Rosen Penev wrote:
> mv_cesa_put_sram() is called explicitly from both the probe error path
> and mv_cesa_remove(). The non-pool ioremap is already devm-managed, but
> dma_map_resource() and gen_pool_dma_alloc() have no devm helpers, so the
> mapping is released by hand. This is error-prone: the error path iterates
> over every engine and can dma_unmap_resource() an uninitialized/zero
> address for engines that were never set up.
>
> Convert the teardown into a devm_add_action_or_reset() callback registered
> only after a mapping is successfully established. The callback fires
> automatically on probe failure (devres rollback) and on device detach,
> after mv_cesa_remove() has already stopped the engine and freed the IRQ,
> so the unmap still happens in a safe order. This deletes the explicit
> mv_cesa_put_sram() calls and the uninitialized-engine bug at once.
>
> Add a struct mv_cesa_dev back-pointer to struct mv_cesa_engine so the
> callback can reach cesa->dev and cesa->sram_size from the engine alone.
>
> Assisted-by: opencode:hy3-free
> Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>
> ---
> drivers/crypto/marvell/cesa/cesa.c | 55 ++++++++++++------------------
> drivers/crypto/marvell/cesa/cesa.h | 2 ++
> 2 files changed, 24 insertions(+), 33 deletions(-)

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