Skip to content

Commit 177360e

Browse files
Tomasz Mońvinodkoul
authored andcommitted
dmaengine: imx-sdma: fix cyclic buffer race condition
Assign buffer ownership to SDMA after invoking descriptor callback to make sure that SDMA does not write to the buffer before it is read by the CPU. Signed-off-by: Tomasz Moń <tomasz.mon@camlingroup.com> Link: https://lore.kernel.org/r/20220117091955.1038937-2-tomasz.mon@camlingroup.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 5b215c2 commit 177360e

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

drivers/dma/imx-sdma.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,6 @@ static void sdma_update_channel_loop(struct sdma_channel *sdmac)
847847
*/
848848

849849
desc->chn_real_count = bd->mode.count;
850-
bd->mode.status |= BD_DONE;
851850
bd->mode.count = desc->period_len;
852851
desc->buf_ptail = desc->buf_tail;
853852
desc->buf_tail = (desc->buf_tail + 1) % desc->num_bd;
@@ -862,6 +861,9 @@ static void sdma_update_channel_loop(struct sdma_channel *sdmac)
862861
dmaengine_desc_get_callback_invoke(&desc->vd.tx, NULL);
863862
spin_lock(&sdmac->vc.lock);
864863

864+
/* Assign buffer ownership to SDMA */
865+
bd->mode.status |= BD_DONE;
866+
865867
if (error)
866868
sdmac->status = old_status;
867869
}

0 commit comments

Comments
 (0)