If allocating the channel zero descriptor fails, sdma_init() disables the clocks without releasing the already allocated channel control and context storage. Free that storage with the matching allocator before returning the error. This issue was found by our static analysis tool under development. Fixes: 1ec1e82f2510 ("dmaengine: Add Freescale i.MX SDMA support") Cc: stable@vger.kernel.org Signed-off-by: Guangshuo Li --- drivers/dma/imx-sdma.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index 36368835a845..9c0087b3b805 100644 --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -2161,7 +2161,7 @@ static int sdma_init(struct sdma_engine *sdma) ret = sdma_request_channel0(sdma); if (ret) - goto err_dma_alloc; + goto free_channel_control; sdma_config_ownership(&sdma->channel[0], false, true, false); @@ -2184,6 +2184,13 @@ static int sdma_init(struct sdma_engine *sdma) return 0; +free_channel_control: + if (sdma->iram_pool) + gen_pool_free(sdma->iram_pool, + (unsigned long)sdma->channel_control, ccbsize); + else + dma_free_coherent(sdma->dev, ccbsize, sdma->channel_control, + ccb_phys); err_dma_alloc: clk_disable(sdma->clk_ahb); disable_clk_ipg: base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 -- 2.43.0