Commit 5a9377cc authored by Peter Ujfalusi's avatar Peter Ujfalusi Committed by Vinod Koul

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: default avatarPeter Ujfalusi <peter.ujfalusi@ti.com>
Link: https://lore.kernel.org/r/20200527070612.636-2-peter.ujfalusi@ti.comSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 9f2f3ce3
...@@ -1753,7 +1753,8 @@ static int udma_alloc_chan_resources(struct dma_chan *chan) ...@@ -1753,7 +1753,8 @@ static int udma_alloc_chan_resources(struct dma_chan *chan)
dev_err(ud->ddev.dev, dev_err(ud->ddev.dev,
"Descriptor pool allocation failed\n"); "Descriptor pool allocation failed\n");
uc->use_dma_pool = false; uc->use_dma_pool = false;
return -ENOMEM; ret = -ENOMEM;
goto err_cleanup;
} }
} }
...@@ -1773,16 +1774,18 @@ static int udma_alloc_chan_resources(struct dma_chan *chan) ...@@ -1773,16 +1774,18 @@ static int udma_alloc_chan_resources(struct dma_chan *chan)
ret = udma_get_chan_pair(uc); ret = udma_get_chan_pair(uc);
if (ret) if (ret)
return ret; goto err_cleanup;
ret = udma_alloc_tx_resources(uc); ret = udma_alloc_tx_resources(uc);
if (ret) if (ret) {
return ret; udma_put_rchan(uc);
goto err_cleanup;
}
ret = udma_alloc_rx_resources(uc); ret = udma_alloc_rx_resources(uc);
if (ret) { if (ret) {
udma_free_tx_resources(uc); udma_free_tx_resources(uc);
return ret; goto err_cleanup;
} }
uc->config.src_thread = ud->psil_base + uc->tchan->id; uc->config.src_thread = ud->psil_base + uc->tchan->id;
...@@ -1800,10 +1803,8 @@ static int udma_alloc_chan_resources(struct dma_chan *chan) ...@@ -1800,10 +1803,8 @@ static int udma_alloc_chan_resources(struct dma_chan *chan)
uc->id); uc->id);
ret = udma_alloc_tx_resources(uc); ret = udma_alloc_tx_resources(uc);
if (ret) { if (ret)
uc->config.remote_thread_id = -1; goto err_cleanup;
return ret;
}
uc->config.src_thread = ud->psil_base + uc->tchan->id; uc->config.src_thread = ud->psil_base + uc->tchan->id;
uc->config.dst_thread = uc->config.remote_thread_id; uc->config.dst_thread = uc->config.remote_thread_id;
...@@ -1820,10 +1821,8 @@ static int udma_alloc_chan_resources(struct dma_chan *chan) ...@@ -1820,10 +1821,8 @@ static int udma_alloc_chan_resources(struct dma_chan *chan)
uc->id); uc->id);
ret = udma_alloc_rx_resources(uc); ret = udma_alloc_rx_resources(uc);
if (ret) { if (ret)
uc->config.remote_thread_id = -1; goto err_cleanup;
return ret;
}
uc->config.src_thread = uc->config.remote_thread_id; uc->config.src_thread = uc->config.remote_thread_id;
uc->config.dst_thread = (ud->psil_base + uc->rchan->id) | uc->config.dst_thread = (ud->psil_base + uc->rchan->id) |
...@@ -1838,7 +1837,9 @@ static int udma_alloc_chan_resources(struct dma_chan *chan) ...@@ -1838,7 +1837,9 @@ static int udma_alloc_chan_resources(struct dma_chan *chan)
/* Can not happen */ /* Can not happen */
dev_err(uc->ud->dev, "%s: chan%d invalid direction (%u)\n", dev_err(uc->ud->dev, "%s: chan%d invalid direction (%u)\n",
__func__, uc->id, uc->config.dir); __func__, uc->id, uc->config.dir);
return -EINVAL; ret = -EINVAL;
goto err_cleanup;
} }
/* check if the channel configuration was successful */ /* check if the channel configuration was successful */
...@@ -1919,7 +1920,7 @@ static int udma_alloc_chan_resources(struct dma_chan *chan) ...@@ -1919,7 +1920,7 @@ static int udma_alloc_chan_resources(struct dma_chan *chan)
err_res_free: err_res_free:
udma_free_tx_resources(uc); udma_free_tx_resources(uc);
udma_free_rx_resources(uc); udma_free_rx_resources(uc);
err_cleanup:
udma_reset_uchan(uc); udma_reset_uchan(uc);
if (uc->use_dma_pool) { if (uc->use_dma_pool) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment