* [PATCH] dmaengine: mediatek: mtk-cqdma: fix list entry type and locking in tx_status
@ 2026-11-30 10:33 Ziheng Wei
2026-11-30 10:45 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Ziheng Wei @ 2026-11-30 10:33 UTC (permalink / raw)
To: Sean Wang, Vinod Koul
Cc: Frank Li, Matthias Brugger, dmaengine, linux-mediatek,
linux-kernel
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@163.com>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] dmaengine: mediatek: mtk-cqdma: fix list entry type and locking in tx_status
2026-11-30 10:33 [PATCH] dmaengine: mediatek: mtk-cqdma: fix list entry type and locking in tx_status Ziheng Wei
@ 2026-11-30 10:45 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-30 10:45 UTC (permalink / raw)
To: Ziheng Wei; +Cc: dmaengine, vkoul, Frank.Li
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dmaengine: mediatek: missing channel check in
mtk_cqdma_find_active_desc()
--
commit 1493321485f8d0688e40f18ce0044f36476d4227
Author: Ziheng Wei <zihengw03@163.com>
dmaengine: mediatek: mtk-cqdma: fix list entry type and locking in tx_status
This commit updates mtk_cqdma_find_active_desc() to iterate over pc->queue
using struct mtk_cqdma_vdesc instead of struct virt_dma_desc, and moves the
cvd->residue read in mtk_cqdma_tx_status() inside the spinlock critical
section.
> diff --git a/drivers/dma/mediatek/mtk-cqdma.c b/drivers/dma/mediatek/mtk-cqdma.c
> index a7000608ddeac..61fd98a9206b0 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;
[Severity: Medium]
Can this match a descriptor belonging to a different virtual channel?
Up to 32 virtual channels are multiplexed across 3 physical channels and
share cvc->pc->queue, while each virtual channel assigns cookies from its
own per-channel counter starting at DMA_MIN_COOKIE. Unlike
mtk_cqdma_is_vchan_active(), this loop does not check that cvd->ch == c, so
mtk_cqdma_tx_status() can match another virtual channel's active descriptor
with the same cookie and report the wrong residue.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130103317.1383850-1-zihengw03@163.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 10:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 10:33 [PATCH] dmaengine: mediatek: mtk-cqdma: fix list entry type and locking in tx_status Ziheng Wei
2026-11-30 10:45 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox