aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/drivers/dma
diff options
context:
space:
mode:
authorTomasz Moń <tomasz.mon@camlingroup.com>2022-01-17 10:19:55 +0100
committerVinod Koul <vkoul@kernel.org>2022-02-15 11:11:06 +0530
commit177360e04b70b1d3937471e42201cdbb831a82da (patch)
treea36f93feae648f04e9995e5d4abff01e5cb2053e /drivers/dma
parentdmaengine: imx-sdma: restart cyclic channel if needed (diff)
downloadwireguard-linux-177360e04b70b1d3937471e42201cdbb831a82da.tar.xz
wireguard-linux-177360e04b70b1d3937471e42201cdbb831a82da.zip
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>
Diffstat (limited to 'drivers/dma')
-rw-r--r--drivers/dma/imx-sdma.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 330ff41cd614..8cc5103193c3 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -847,7 +847,6 @@ static void sdma_update_channel_loop(struct sdma_channel *sdmac)
*/
desc->chn_real_count = bd->mode.count;
- bd->mode.status |= BD_DONE;
bd->mode.count = desc->period_len;
desc->buf_ptail = desc->buf_tail;
desc->buf_tail = (desc->buf_tail + 1) % desc->num_bd;
@@ -862,6 +861,9 @@ static void sdma_update_channel_loop(struct sdma_channel *sdmac)
dmaengine_desc_get_callback_invoke(&desc->vd.tx, NULL);
spin_lock(&sdmac->vc.lock);
+ /* Assign buffer ownership to SDMA */
+ bd->mode.status |= BD_DONE;
+
if (error)
sdmac->status = old_status;
}