Skip to content

Commit

Permalink
crypto: sa2ul - Fix leaks on failure paths with sa_dma_init()
Browse files Browse the repository at this point in the history
[ Upstream commit 4c0716e ]

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: 7694b6c ("crypto: sa2ul - Add crypto driver")
Signed-off-by: Suman Anna <s-anna@ti.com>
Reviewed-by: Tero Kristo <kristo@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
sumananna authored and gregkh committed Jul 14, 2021
1 parent 9d5db40 commit 918861a
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions drivers/crypto/sa2ul.c
Original file line number Diff line number Diff line change
Expand Up @@ -2275,9 +2275,9 @@ static int sa_dma_init(struct sa_crypto_data *dd)

dd->dma_rx2 = dma_request_chan(dd->dev, "rx2");
if (IS_ERR(dd->dma_rx2)) {
dma_release_channel(dd->dma_rx1);
return dev_err_probe(dd->dev, PTR_ERR(dd->dma_rx2),
"Unable to request rx2 DMA channel\n");
ret = dev_err_probe(dd->dev, PTR_ERR(dd->dma_rx2),
"Unable to request rx2 DMA channel\n");
goto err_dma_rx2;
}

dd->dma_tx = dma_request_chan(dd->dev, "tx");
Expand All @@ -2298,28 +2298,31 @@ static int sa_dma_init(struct sa_crypto_data *dd)
if (ret) {
dev_err(dd->dev, "can't configure IN dmaengine slave: %d\n",
ret);
return ret;
goto err_dma_config;
}

ret = dmaengine_slave_config(dd->dma_rx2, &cfg);
if (ret) {
dev_err(dd->dev, "can't configure IN dmaengine slave: %d\n",
ret);
return ret;
goto err_dma_config;
}

ret = dmaengine_slave_config(dd->dma_tx, &cfg);
if (ret) {
dev_err(dd->dev, "can't configure OUT dmaengine slave: %d\n",
ret);
return ret;
goto err_dma_config;
}

return 0;

err_dma_config:
dma_release_channel(dd->dma_tx);
err_dma_tx:
dma_release_channel(dd->dma_rx1);
dma_release_channel(dd->dma_rx2);
err_dma_rx2:
dma_release_channel(dd->dma_rx1);

return ret;
}
Expand Down Expand Up @@ -2364,7 +2367,7 @@ static int sa_ul_probe(struct platform_device *pdev)
sa_init_mem(dev_data);
ret = sa_dma_init(dev_data);
if (ret)
goto disable_pm_runtime;
goto destroy_dma_pool;

spin_lock_init(&dev_data->scid_lock);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Expand Down Expand Up @@ -2394,9 +2397,9 @@ static int sa_ul_probe(struct platform_device *pdev)
dma_release_channel(dev_data->dma_rx1);
dma_release_channel(dev_data->dma_tx);

destroy_dma_pool:
dma_pool_destroy(dev_data->sc_pool);

disable_pm_runtime:
pm_runtime_put_sync(&pdev->dev);
pm_runtime_disable(&pdev->dev);

Expand Down

0 comments on commit 918861a

Please sign in to comment.