[PATCH] dmaengine: mediatek: mtk-cqdma: fix list entry type and locking in tx_status

From: Ziheng Wei

Date: Mon Nov 30 2026 - 05:33:51 EST


mtk_cqdma_issue_vchan_pending() links active descriptors onto pc->queue via
struct mtk_cqdma_vdesc::node, but mtk_cqdma_find_active_desc() walks
pc->queue using struct virt_dma_desc::node. This shifts each recovered
descriptor pointer so vd->tx.cookie reads the wrong field; if it matches
cookie, to_cqdma_vdesc(vd)->residue reads past the end of the allocation,
and otherwise active transfers falsely report zero residue.

mtk_cqdma_tx_status() also reads cvd->residue after dropping vc.lock and
pc->lock, racing with tasklet completion and descriptor free.

Walk pc->queue as struct mtk_cqdma_vdesc and read cvd->residue under lock.

Found by LLM-assisted static analysis and runtime-tested in QEMU+KASAN
(slab-out-of-bounds before the fix; 0 KASAN findings after).

Fixes: b1f01e48df5a ("dmaengine: mediatek: Add MediaTek Command-Queue DMA controller for MT6765 SoC")
Signed-off-by: Ziheng Wei <zihengw03@xxxxxxx>
---
drivers/dma/mediatek/mtk-cqdma.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/dma/mediatek/mtk-cqdma.c b/drivers/dma/mediatek/mtk-cqdma.c
index a7000608d..61fd98a92 100644
--- a/drivers/dma/mediatek/mtk-cqdma.c
+++ b/drivers/dma/mediatek/mtk-cqdma.c
@@ -419,12 +419,12 @@ static struct virt_dma_desc *mtk_cqdma_find_active_desc(struct dma_chan *c,
dma_cookie_t cookie)
{
struct mtk_cqdma_vchan *cvc = to_cqdma_vchan(c);
+ struct mtk_cqdma_vdesc *cvd;
struct virt_dma_desc *vd;

- list_for_each_entry(vd, &cvc->pc->queue, node)
- if (vd->tx.cookie == cookie) {
- return vd;
- }
+ list_for_each_entry(cvd, &cvc->pc->queue, node)
+ if (cvd->vd.tx.cookie == cookie)
+ return &cvd->vd;

list_for_each_entry(vd, &cvc->vc.desc_issued, node)
if (vd->tx.cookie == cookie)
@@ -451,13 +451,12 @@ static enum dma_status mtk_cqdma_tx_status(struct dma_chan *c,
spin_lock_irqsave(&cvc->pc->lock, flags);
spin_lock(&cvc->vc.lock);
vd = mtk_cqdma_find_active_desc(c, cookie);
- spin_unlock(&cvc->vc.lock);
- spin_unlock_irqrestore(&cvc->pc->lock, flags);
-
if (vd) {
cvd = to_cqdma_vdesc(vd);
bytes = cvd->residue;
}
+ spin_unlock(&cvc->vc.lock);
+ spin_unlock_irqrestore(&cvc->pc->lock, flags);

dma_set_residue(txstate, bytes);


base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
--
2.43.0