Skip to content

Commit 37c2c83

Browse files
Conchy-Conchybroonie
authored andcommitted
spi: uniphier: fix reference count leak in uniphier_spi_probe()
The issue happens in several error paths in uniphier_spi_probe(). When either dma_get_slave_caps() or devm_spi_register_master() returns an error code, the function forgets to decrease the refcount of both `dma_rx` and `dma_tx` objects, which may lead to refcount leaks. Fix it by decrementing the reference count of specific objects in those error paths. 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> Reviewed-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com> Fixes: 28d1ddd ("spi: uniphier: Add DMA transfer mode support") Link: https://lore.kernel.org/r/20220125101214.35677-1-xiongx18@fudan.edu.cn Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent e937440 commit 37c2c83

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

drivers/spi/spi-uniphier.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ static int uniphier_spi_probe(struct platform_device *pdev)
726726
if (ret) {
727727
dev_err(&pdev->dev, "failed to get TX DMA capacities: %d\n",
728728
ret);
729-
goto out_disable_clk;
729+
goto out_release_dma;
730730
}
731731
dma_tx_burst = caps.max_burst;
732732
}
@@ -735,7 +735,7 @@ static int uniphier_spi_probe(struct platform_device *pdev)
735735
if (IS_ERR_OR_NULL(master->dma_rx)) {
736736
if (PTR_ERR(master->dma_rx) == -EPROBE_DEFER) {
737737
ret = -EPROBE_DEFER;
738-
goto out_disable_clk;
738+
goto out_release_dma;
739739
}
740740
master->dma_rx = NULL;
741741
dma_rx_burst = INT_MAX;
@@ -744,7 +744,7 @@ static int uniphier_spi_probe(struct platform_device *pdev)
744744
if (ret) {
745745
dev_err(&pdev->dev, "failed to get RX DMA capacities: %d\n",
746746
ret);
747-
goto out_disable_clk;
747+
goto out_release_dma;
748748
}
749749
dma_rx_burst = caps.max_burst;
750750
}
@@ -753,10 +753,20 @@ static int uniphier_spi_probe(struct platform_device *pdev)
753753

754754
ret = devm_spi_register_master(&pdev->dev, master);
755755
if (ret)
756-
goto out_disable_clk;
756+
goto out_release_dma;
757757

758758
return 0;
759759

760+
out_release_dma:
761+
if (!IS_ERR_OR_NULL(master->dma_rx)) {
762+
dma_release_channel(master->dma_rx);
763+
master->dma_rx = NULL;
764+
}
765+
if (!IS_ERR_OR_NULL(master->dma_tx)) {
766+
dma_release_channel(master->dma_tx);
767+
master->dma_tx = NULL;
768+
}
769+
760770
out_disable_clk:
761771
clk_disable_unprepare(priv->clk);
762772

0 commit comments

Comments
 (0)