Skip to content

Commit 8105c2a

Browse files
Conchy-ConchyUlf Hansson
authored andcommitted
mmc: moxart: Fix reference count leaks in moxart_probe
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>
1 parent f83c18c commit 8105c2a

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
@@ -621,6 +621,14 @@ static int moxart_probe(struct platform_device *pdev)
621621
ret = -EPROBE_DEFER;
622622
goto out;
623623
}
624+
if (!IS_ERR(host->dma_chan_tx)) {
625+
dma_release_channel(host->dma_chan_tx);
626+
host->dma_chan_tx = NULL;
627+
}
628+
if (!IS_ERR(host->dma_chan_rx)) {
629+
dma_release_channel(host->dma_chan_rx);
630+
host->dma_chan_rx = NULL;
631+
}
624632
dev_dbg(dev, "PIO mode transfer enabled\n");
625633
host->have_dma = false;
626634
} else {
@@ -675,6 +683,10 @@ static int moxart_probe(struct platform_device *pdev)
675683
return 0;
676684

677685
out:
686+
if (!IS_ERR_OR_NULL(host->dma_chan_tx))
687+
dma_release_channel(host->dma_chan_tx);
688+
if (!IS_ERR_OR_NULL(host->dma_chan_rx))
689+
dma_release_channel(host->dma_chan_rx);
678690
if (mmc)
679691
mmc_free_host(mmc);
680692
return ret;
@@ -687,9 +699,9 @@ static int moxart_remove(struct platform_device *pdev)
687699

688700
dev_set_drvdata(&pdev->dev, NULL);
689701

690-
if (!IS_ERR(host->dma_chan_tx))
702+
if (!IS_ERR_OR_NULL(host->dma_chan_tx))
691703
dma_release_channel(host->dma_chan_tx);
692-
if (!IS_ERR(host->dma_chan_rx))
704+
if (!IS_ERR_OR_NULL(host->dma_chan_rx))
693705
dma_release_channel(host->dma_chan_rx);
694706
mmc_remove_host(mmc);
695707
mmc_free_host(mmc);

0 commit comments

Comments
 (0)