Commit 4c0716ee authored by Suman Anna's avatar Suman Anna Committed by Herbert Xu

crypto: sa2ul - Fix leaks on failure paths with sa_dma_init()

The sa_dma_init() function doesn't release the requested dma channels
on all failure paths. Any failure in this function also ends up
leaking the dma pool created in sa_init_mem() in the sa_ul_probe()
function. Fix all of these issues.

Fixes: 7694b6ca ("crypto: sa2ul - Add crypto driver")
Signed-off-by: default avatarSuman Anna <s-anna@ti.com>
Reviewed-by: default avatarTero Kristo <kristo@kernel.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 5c93a2eb
...@@ -2300,9 +2300,9 @@ static int sa_dma_init(struct sa_crypto_data *dd) ...@@ -2300,9 +2300,9 @@ static int sa_dma_init(struct sa_crypto_data *dd)
dd->dma_rx2 = dma_request_chan(dd->dev, "rx2"); dd->dma_rx2 = dma_request_chan(dd->dev, "rx2");
if (IS_ERR(dd->dma_rx2)) { if (IS_ERR(dd->dma_rx2)) {
dma_release_channel(dd->dma_rx1); ret = dev_err_probe(dd->dev, PTR_ERR(dd->dma_rx2),
return dev_err_probe(dd->dev, PTR_ERR(dd->dma_rx2),
"Unable to request rx2 DMA channel\n"); "Unable to request rx2 DMA channel\n");
goto err_dma_rx2;
} }
dd->dma_tx = dma_request_chan(dd->dev, "tx"); dd->dma_tx = dma_request_chan(dd->dev, "tx");
...@@ -2323,28 +2323,31 @@ static int sa_dma_init(struct sa_crypto_data *dd) ...@@ -2323,28 +2323,31 @@ static int sa_dma_init(struct sa_crypto_data *dd)
if (ret) { if (ret) {
dev_err(dd->dev, "can't configure IN dmaengine slave: %d\n", dev_err(dd->dev, "can't configure IN dmaengine slave: %d\n",
ret); ret);
return ret; goto err_dma_config;
} }
ret = dmaengine_slave_config(dd->dma_rx2, &cfg); ret = dmaengine_slave_config(dd->dma_rx2, &cfg);
if (ret) { if (ret) {
dev_err(dd->dev, "can't configure IN dmaengine slave: %d\n", dev_err(dd->dev, "can't configure IN dmaengine slave: %d\n",
ret); ret);
return ret; goto err_dma_config;
} }
ret = dmaengine_slave_config(dd->dma_tx, &cfg); ret = dmaengine_slave_config(dd->dma_tx, &cfg);
if (ret) { if (ret) {
dev_err(dd->dev, "can't configure OUT dmaengine slave: %d\n", dev_err(dd->dev, "can't configure OUT dmaengine slave: %d\n",
ret); ret);
return ret; goto err_dma_config;
} }
return 0; return 0;
err_dma_config:
dma_release_channel(dd->dma_tx);
err_dma_tx: err_dma_tx:
dma_release_channel(dd->dma_rx1);
dma_release_channel(dd->dma_rx2); dma_release_channel(dd->dma_rx2);
err_dma_rx2:
dma_release_channel(dd->dma_rx1);
return ret; return ret;
} }
...@@ -2414,7 +2417,7 @@ static int sa_ul_probe(struct platform_device *pdev) ...@@ -2414,7 +2417,7 @@ static int sa_ul_probe(struct platform_device *pdev)
sa_init_mem(dev_data); sa_init_mem(dev_data);
ret = sa_dma_init(dev_data); ret = sa_dma_init(dev_data);
if (ret) if (ret)
goto disable_pm_runtime; goto destroy_dma_pool;
match = of_match_node(of_match, dev->of_node); match = of_match_node(of_match, dev->of_node);
if (!match) { if (!match) {
...@@ -2454,9 +2457,9 @@ static int sa_ul_probe(struct platform_device *pdev) ...@@ -2454,9 +2457,9 @@ static int sa_ul_probe(struct platform_device *pdev)
dma_release_channel(dev_data->dma_rx1); dma_release_channel(dev_data->dma_rx1);
dma_release_channel(dev_data->dma_tx); dma_release_channel(dev_data->dma_tx);
destroy_dma_pool:
dma_pool_destroy(dev_data->sc_pool); dma_pool_destroy(dev_data->sc_pool);
disable_pm_runtime:
pm_runtime_put_sync(&pdev->dev); pm_runtime_put_sync(&pdev->dev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
......
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