dmaengine: sprd: Add validation of current descriptor in irq handler [Linux 5.2]

dmaengine: sprd: Add validation of current descriptor in irq handler [Linux 5.2]

This Linux kernel change "dmaengine: sprd: Add validation of current descriptor in irq handler" is included in the Linux 5.2 release. This change is authored by Baolin Wang <baolin.wang [at] linaro.org> on Mon May 6 15:28:29 2019 +0800. The commit for this change in Linux stable tree is 58152b0 (patch).

dmaengine: sprd: Add validation of current descriptor in irq handler

When user terminates one DMA channel to free all its descriptors, but
at the same time one transaction interrupt was triggered possibly, now
we should not handle this interrupt by validating if the 'schan->cur_desc'
was set as NULL to avoid crashing the kernel.

Signed-off-by: Baolin Wang <[email protected]>
Signed-off-by: Vinod Koul <[email protected]>

There are 9 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/dma/sprd-dma.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/sprd-dma.c b/drivers/dma/sprd-dma.c
index e29342a..431e289 100644
--- a/drivers/dma/sprd-dma.c
+++ b/drivers/dma/sprd-dma.c
@@ -552,12 +552,17 @@ static irqreturn_t dma_irq_handle(int irq, void *dev_id)
        schan = &sdev->channels[i];

        spin_lock(&schan->vc.lock);
+
+       sdesc = schan->cur_desc;
+       if (!sdesc) {
+           spin_unlock(&schan->vc.lock);
+           return IRQ_HANDLED;
+       }
+
        int_type = sprd_dma_get_int_type(schan);
        req_type = sprd_dma_get_req_type(schan);
        sprd_dma_clear_int(schan);

-       sdesc = schan->cur_desc;
-
        /* cyclic mode schedule callback */
        cyclic = schan->linklist.phy_addr ? true : false;
        if (cyclic == true) {

Leave a Reply

Your email address will not be published. Required fields are marked *