MLK-25473-4: dmaengine: imx-sdma: fix kernel hang at spi probe
authorRobin Gong <yibin.gong@nxp.com>
Fri, 30 Apr 2021 13:59:55 +0000 (21:59 +0800)
committerRobin Gong <yibin.gong@nxp.com>
Fri, 30 Apr 2021 15:09:51 +0000 (23:09 +0800)
spi driver would request dma channel and free dma channel if -EPROBE_DEFER
happen after request dma channel, then kernel hang in free dma channel
since sdma hardware not initialized including clock. Directly ignore to
touch any hardware in this case.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
Reviewed-by: Shengjiu Wang <shengjiu.wang@nxp.com>
drivers/dma/imx-sdma.c

index 9598058..769841e 100644 (file)
@@ -1628,7 +1628,9 @@ static int sdma_runtime_resume(struct device *dev)
        /* Initializes channel's priorities */
        sdma_set_channel_priority(&sdma->channel[0], 7);
 
-       if (sdma_load_script(sdma))
+       if (!sdma->fw_data)
+               dev_dbg(sdma->dev, "firmware not ready.\n");
+       else if (sdma_load_script(sdma))
                dev_warn(sdma->dev, "failed to load script.\n");
 
        sdma->is_on = true;
@@ -1694,6 +1696,20 @@ static void sdma_free_chan_resources(struct dma_chan *chan)
 {
        struct sdma_channel *sdmac = to_sdma_chan(chan);
 
+       /*
+        * Per fw_data is null which means firmware not loaded and sdma
+        * not initialized, directly return. This happens in below case:
+        *
+        * -- driver request dma chan in probe phase, after that driver
+        *    fall into -EPROBE_DEFER and free channel again without
+        *    anything else about dma, so just return directly, otherwise
+        *    kernel could hang since dma hardware not ready if drvdata->
+        *    pm_runtime is false.
+        *
+        */
+       if (unlikely(!sdmac->sdma->fw_data))
+               return;
+
        if (sdmac->sdma->drvdata->pm_runtime)
                pm_runtime_get_sync(sdmac->sdma->dev);