Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Tomasz Moń and committed by
Vinod Koul
177360e0 5b215c28

+3 -1
+3 -1
drivers/dma/imx-sdma.c
··· 847 847 */ 848 848 849 849 desc->chn_real_count = bd->mode.count; 850 - bd->mode.status |= BD_DONE; 851 850 bd->mode.count = desc->period_len; 852 851 desc->buf_ptail = desc->buf_tail; 853 852 desc->buf_tail = (desc->buf_tail + 1) % desc->num_bd; ··· 860 861 spin_unlock(&sdmac->vc.lock); 861 862 dmaengine_desc_get_callback_invoke(&desc->vd.tx, NULL); 862 863 spin_lock(&sdmac->vc.lock); 864 + 865 + /* Assign buffer ownership to SDMA */ 866 + bd->mode.status |= BD_DONE; 863 867 864 868 if (error) 865 869 sdmac->status = old_status;