Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dmaengine: mediatek:Fix PM usage reference leak of mtk_uart_apdma_alloc_chan_resources

pm_runtime_get_sync will increment pm usage counter even it failed.
Forgetting to putting operation will result in reference leak here.
We fix it:
1) Replacing it with pm_runtime_resume_and_get to keep usage counter
balanced.
2) Add putting operation before returning error.

Fixes:9135408c3ace4 ("dmaengine: mediatek: Add MediaTek UART APDMA support")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Link: https://lore.kernel.org/r/20220319022142.142709-1-zhangqilong3@huawei.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

zhangqilong and committed by
Vinod Koul
545b2baa 7104b9cb

+6 -3
+6 -3
drivers/dma/mediatek/mtk-uart-apdma.c
··· 274 274 unsigned int status; 275 275 int ret; 276 276 277 - ret = pm_runtime_get_sync(mtkd->ddev.dev); 277 + ret = pm_runtime_resume_and_get(mtkd->ddev.dev); 278 278 if (ret < 0) { 279 279 pm_runtime_put_noidle(chan->device->dev); 280 280 return ret; ··· 288 288 ret = readx_poll_timeout(readl, c->base + VFF_EN, 289 289 status, !status, 10, 100); 290 290 if (ret) 291 - return ret; 291 + goto err_pm; 292 292 293 293 ret = request_irq(c->irq, mtk_uart_apdma_irq_handler, 294 294 IRQF_TRIGGER_NONE, KBUILD_MODNAME, chan); 295 295 if (ret < 0) { 296 296 dev_err(chan->device->dev, "Can't request dma IRQ\n"); 297 - return -EINVAL; 297 + ret = -EINVAL; 298 + goto err_pm; 298 299 } 299 300 300 301 if (mtkd->support_33bits) 301 302 mtk_uart_apdma_write(c, VFF_4G_SUPPORT, VFF_4G_SUPPORT_CLR_B); 302 303 304 + err_pm: 305 + pm_runtime_put_noidle(mtkd->ddev.dev); 303 306 return ret; 304 307 } 305 308