Re: [PATCH 09/10] dmaengine: jz4780: Fix descriptor cleanup on hwdesc setup failure
From: Paul Cercueil
Date: Tue Nov 17 2026 - 11:26:19 EST
Hi Lee,
Le mercredi 11 novembre 2026 à 21:52 +0000, Lee Jones a écrit :
> When jz4780_dma_setup_hwdesc() fails in jz4780_dma_prep_slave_sg() or
> jz4780_dma_prep_dma_cyclic(), the error paths pass &jzchan->desc->vdesc
> to jz4780_dma_desc_free() instead of the newly allocated &desc->vdesc.
> This leaks the newly allocated descriptor and either dereferences NULL
> when jzchan->desc is NULL or frees the currently active descriptor while
> it is still in flight. Furthermore, jz4780_dma_desc_free() derives
> jzchan from vdesc->tx.chan, which is not yet initialised before
> vchan_tx_prep() is called.
>
> Initialise desc->vdesc.tx.chan in jz4780_dma_desc_alloc() and pass
> &desc->vdesc to jz4780_dma_desc_free() in the preparation error paths.
>
> Fixes: d894fc6046fe ("dmaengine: jz4780: add driver for the Ingenic JZ4780 DMA
> controller")
> Closes: https://sashiko.dev/#/bug/linux-b39121ef-5ffb-401a-9d04-0afccd467bde
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
Reviewed-by: Paul Cercueil <paul@xxxxxxxxxxxxxxx>
Cheers,
-Paul
> ---
> drivers/dma/dma-jz4780.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dma/dma-jz4780.c b/drivers/dma/dma-jz4780.c
> index ac2094e65ecf..c3974c825ba7 100644
> --- a/drivers/dma/dma-jz4780.c
> +++ b/drivers/dma/dma-jz4780.c
> @@ -248,6 +248,7 @@ jz4780_dma_desc_alloc(struct jz4780_dma_chan *jzchan,
> unsigned int count,
> return NULL;
> }
>
> + desc->vdesc.tx.chan = &jzchan->vchan.chan;
> desc->count = count;
> desc->type = type;
>
> @@ -379,7 +380,7 @@ static struct dma_async_tx_descriptor
> *jz4780_dma_prep_slave_sg(
> sg_dma_len(&sgl[i]),
> direction);
> if (err < 0) {
> - jz4780_dma_desc_free(&jzchan->desc->vdesc);
> + jz4780_dma_desc_free(&desc->vdesc);
> return NULL;
> }
>
> @@ -426,7 +427,7 @@ static struct dma_async_tx_descriptor
> *jz4780_dma_prep_dma_cyclic(
> err = jz4780_dma_setup_hwdesc(jzchan, &desc->desc[i],
> buf_addr,
> period_len, direction);
> if (err < 0) {
> - jz4780_dma_desc_free(&jzchan->desc->vdesc);
> + jz4780_dma_desc_free(&desc->vdesc);
> return NULL;
> }
>