dmaengine: stm32-mdma: abort resume if no ongoing transfer
authorAmelie Delaunay <amelie.delaunay@foss.st.com>
Wed, 4 Oct 2023 16:35:28 +0000 (18:35 +0200)
committerVinod Koul <vkoul@kernel.org>
Mon, 9 Oct 2023 05:40:30 +0000 (11:10 +0530)
chan->desc can be null, if transfer is terminated when resume is called,
leading to a NULL pointer when retrieving the hwdesc.
To avoid this case, check that chan->desc is not null and channel is
disabled (transfer previously paused or terminated).

Fixes: a4ffb13c8946 ("dmaengine: Add STM32 MDMA driver")
Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20231004163531.2864160-1-amelie.delaunay@foss.st.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/stm32-mdma.c

index 0de2340..cc6f4b0 100644 (file)
@@ -1236,6 +1236,10 @@ static int stm32_mdma_resume(struct dma_chan *c)
        unsigned long flags;
        u32 status, reg;
 
+       /* Transfer can be terminated */
+       if (!chan->desc || (stm32_mdma_read(dmadev, STM32_MDMA_CCR(chan->id)) & STM32_MDMA_CCR_EN))
+               return -EPERM;
+
        hwdesc = chan->desc->node[chan->curr_hwdesc].hwdesc;
 
        spin_lock_irqsave(&chan->vchan.lock, flags);