Skip to content

Commit 219df0f

Browse files
Conchy-Conchygregkh
authored andcommitted
mmc: moxart: Fix reference count leaks in moxart_probe
[ Upstream commit 8105c2a ] The issue happens in several error handling paths on two refcounted object related to the object "host" (dma_chan_rx, dma_chan_tx). In these paths, the function forgets to decrement one or both objects' reference count increased earlier by dma_request_chan(), causing reference count leaks. Fix it by balancing the refcounts of both objects in some error handling paths. In correspondence with the changes in moxart_probe(), IS_ERR() is replaced with IS_ERR_OR_NULL() in moxart_remove() as well. Signed-off-by: Xin Xiong <xiongx18@fudan.edu.cn> Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn> Signed-off-by: Xin Tan <tanxin.ctf@gmail.com> Link: https://lore.kernel.org/r/20211009041918.28419-1-xiongx18@fudan.edu.cn Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 38608d3 commit 219df0f

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

drivers/mmc/host/moxart-mmc.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,14 @@ static int moxart_probe(struct platform_device *pdev)
624624
ret = -EPROBE_DEFER;
625625
goto out;
626626
}
627+
if (!IS_ERR(host->dma_chan_tx)) {
628+
dma_release_channel(host->dma_chan_tx);
629+
host->dma_chan_tx = NULL;
630+
}
631+
if (!IS_ERR(host->dma_chan_rx)) {
632+
dma_release_channel(host->dma_chan_rx);
633+
host->dma_chan_rx = NULL;
634+
}
627635
dev_dbg(dev, "PIO mode transfer enabled\n");
628636
host->have_dma = false;
629637
} else {
@@ -678,6 +686,10 @@ static int moxart_probe(struct platform_device *pdev)
678686
return 0;
679687

680688
out:
689+
if (!IS_ERR_OR_NULL(host->dma_chan_tx))
690+
dma_release_channel(host->dma_chan_tx);
691+
if (!IS_ERR_OR_NULL(host->dma_chan_rx))
692+
dma_release_channel(host->dma_chan_rx);
681693
if (mmc)
682694
mmc_free_host(mmc);
683695
return ret;
@@ -690,9 +702,9 @@ static int moxart_remove(struct platform_device *pdev)
690702

691703
dev_set_drvdata(&pdev->dev, NULL);
692704

693-
if (!IS_ERR(host->dma_chan_tx))
705+
if (!IS_ERR_OR_NULL(host->dma_chan_tx))
694706
dma_release_channel(host->dma_chan_tx);
695-
if (!IS_ERR(host->dma_chan_rx))
707+
if (!IS_ERR_OR_NULL(host->dma_chan_rx))
696708
dma_release_channel(host->dma_chan_rx);
697709
mmc_remove_host(mmc);
698710
mmc_free_host(mmc);

0 commit comments

Comments
 (0)