From: Robin Gong Date: Fri, 30 Apr 2021 13:59:55 +0000 (+0800) Subject: MLK-25473-4: dmaengine: imx-sdma: fix kernel hang at spi probe X-Git-Tag: rel_imx_5.10.35_2.0.0-somdevices.0~124 X-Git-Url: https://git.somdevices.com/?a=commitdiff_plain;h=03b457761fcda068390be5ce80e99fa72582962e;p=linux.git MLK-25473-4: dmaengine: imx-sdma: fix kernel hang at spi probe 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 Reviewed-by: Shengjiu Wang --- diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index 9598058b08f7..769841e5d74f 100644 --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -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);