mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 13:14:02 +02:00
dmaengine: sun6i: fix undefined behaviour in sun6i_dma_tx_status
sun6i_dma_tx_status() calls vchan_find_desc() to look up the virtual
descriptor for a given cookie, before checking whether the pointer
vd is NULL:
vd = vchan_find_desc(&vchan->vc, cookie);
txd = to_sun6i_desc(&vd->tx); /* vd may be NULL here */
if (vd) {
for (lli = txd->v_lli; ...)
vchan_find_desc() returns NULL when the descriptor has already been
completed or is in-flight on a physical channel and no longer present
in the virtual channel's descriptor list. When vd is NULL,
to_sun6i_desc() is called unconditionally on &vd->tx before the NULL
check, which is undefined behaviour. Move the call inside the if (vd)
guard to ensure it is only reached with a valid pointer.
vd = vchan_find_desc(&vchan->vc, cookie);
if (vd) {
struct sun6i_desc *txd = to_sun6i_desc(&vd->tx);
for (lli = txd->v_lli; ...)
Fixes: 5558593087 ("dmaengine: sun6i: Add driver for the Allwinner A31 DMA controller")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-sonnet-4-6
Signed-off-by: Christian Lugnberg <christian.lugnberg@soundtrack.io>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Link: https://patch.msgid.link/20260817135723.12807-3-christian.lugnberg@soundtrack.io
Signed-off-by: Vinod Koul <vkoul@kernel.org>
This commit is contained in:
parent
c90b6973da
commit
9096bdc8d9
|
|
@ -981,7 +981,6 @@ static enum dma_status sun6i_dma_tx_status(struct dma_chan *chan,
|
|||
struct sun6i_pchan *pchan = vchan->phy;
|
||||
struct sun6i_dma_lli *lli;
|
||||
struct virt_dma_desc *vd;
|
||||
struct sun6i_desc *txd;
|
||||
enum dma_status ret;
|
||||
unsigned long flags;
|
||||
size_t bytes = 0;
|
||||
|
|
@ -993,9 +992,9 @@ static enum dma_status sun6i_dma_tx_status(struct dma_chan *chan,
|
|||
spin_lock_irqsave(&vchan->vc.lock, flags);
|
||||
|
||||
vd = vchan_find_desc(&vchan->vc, cookie);
|
||||
txd = to_sun6i_desc(&vd->tx);
|
||||
|
||||
if (vd) {
|
||||
struct sun6i_desc *txd = to_sun6i_desc(&vd->tx);
|
||||
for (lli = txd->v_lli; lli != NULL; lli = lli->v_lli_next)
|
||||
bytes += lli->len;
|
||||
} else if (!pchan || !pchan->desc) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user