Skip to content

Commit 5a9377c

Browse files
Peter Ujfalusivinodkoul
authored andcommitted
dmaengine: ti: k3-udma: Fix cleanup code for alloc_chan_resources
Some of the earlier errors should be sent to the error cleanup path to make sure that the uchan struct is reset, the dma_pool (if allocated) is released and memcpy channel pairs are released in a correct way. Signed-off-by: Peter Ujfalusi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 9f2f3ce commit 5a9377c

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

drivers/dma/ti/k3-udma.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,8 @@ static int udma_alloc_chan_resources(struct dma_chan *chan)
17531753
dev_err(ud->ddev.dev,
17541754
"Descriptor pool allocation failed\n");
17551755
uc->use_dma_pool = false;
1756-
return -ENOMEM;
1756+
ret = -ENOMEM;
1757+
goto err_cleanup;
17571758
}
17581759
}
17591760

@@ -1773,16 +1774,18 @@ static int udma_alloc_chan_resources(struct dma_chan *chan)
17731774

17741775
ret = udma_get_chan_pair(uc);
17751776
if (ret)
1776-
return ret;
1777+
goto err_cleanup;
17771778

17781779
ret = udma_alloc_tx_resources(uc);
1779-
if (ret)
1780-
return ret;
1780+
if (ret) {
1781+
udma_put_rchan(uc);
1782+
goto err_cleanup;
1783+
}
17811784

17821785
ret = udma_alloc_rx_resources(uc);
17831786
if (ret) {
17841787
udma_free_tx_resources(uc);
1785-
return ret;
1788+
goto err_cleanup;
17861789
}
17871790

17881791
uc->config.src_thread = ud->psil_base + uc->tchan->id;
@@ -1800,10 +1803,8 @@ static int udma_alloc_chan_resources(struct dma_chan *chan)
18001803
uc->id);
18011804

18021805
ret = udma_alloc_tx_resources(uc);
1803-
if (ret) {
1804-
uc->config.remote_thread_id = -1;
1805-
return ret;
1806-
}
1806+
if (ret)
1807+
goto err_cleanup;
18071808

18081809
uc->config.src_thread = ud->psil_base + uc->tchan->id;
18091810
uc->config.dst_thread = uc->config.remote_thread_id;
@@ -1820,10 +1821,8 @@ static int udma_alloc_chan_resources(struct dma_chan *chan)
18201821
uc->id);
18211822

18221823
ret = udma_alloc_rx_resources(uc);
1823-
if (ret) {
1824-
uc->config.remote_thread_id = -1;
1825-
return ret;
1826-
}
1824+
if (ret)
1825+
goto err_cleanup;
18271826

18281827
uc->config.src_thread = uc->config.remote_thread_id;
18291828
uc->config.dst_thread = (ud->psil_base + uc->rchan->id) |
@@ -1838,7 +1837,9 @@ static int udma_alloc_chan_resources(struct dma_chan *chan)
18381837
/* Can not happen */
18391838
dev_err(uc->ud->dev, "%s: chan%d invalid direction (%u)\n",
18401839
__func__, uc->id, uc->config.dir);
1841-
return -EINVAL;
1840+
ret = -EINVAL;
1841+
goto err_cleanup;
1842+
18421843
}
18431844

18441845
/* check if the channel configuration was successful */
@@ -1919,7 +1920,7 @@ static int udma_alloc_chan_resources(struct dma_chan *chan)
19191920
err_res_free:
19201921
udma_free_tx_resources(uc);
19211922
udma_free_rx_resources(uc);
1922-
1923+
err_cleanup:
19231924
udma_reset_uchan(uc);
19241925

19251926
if (uc->use_dma_pool) {

0 commit comments

Comments
 (0)