linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cypto: mediatek - fix leaks in mtk_desc_ring_alloc
@ 2020-09-03  6:38 Xiaoliang Pang
  2020-09-04  7:21 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Xiaoliang Pang @ 2020-09-03  6:38 UTC (permalink / raw)
  To: herbert, davem, matthias.bgg, swboyd, yuehaibing, tianjia.zhang,
	ryder.lee
  Cc: linux-crypto, linux-arm-kernel, linux-mediatek, linux-kernel,
	dawning.pang

In the init loop, if an error occurs in function 'dma_alloc_coherent',
then goto the err_cleanup section,
in the cleanup loop, after run i--, 
the struct mtk_ring rising[i] will not be released,
causing a memory leak

Signed-off-by: Xiaoliang Pang <dawning.pang@gmail.com>
---
 drivers/crypto/mediatek/mtk-platform.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/mediatek/mtk-platform.c b/drivers/crypto/mediatek/mtk-platform.c
index 7e3ad085b5bd..05d341e4a696 100644
--- a/drivers/crypto/mediatek/mtk-platform.c
+++ b/drivers/crypto/mediatek/mtk-platform.c
@@ -469,7 +469,7 @@ static int mtk_desc_ring_alloc(struct mtk_cryp *cryp)
 	return 0;
 
 err_cleanup:
-	for (; i--; ) {
+	for (; i >= 0; --i) {
 		dma_free_coherent(cryp->dev, MTK_DESC_RING_SZ,
 				  ring[i]->res_base, ring[i]->res_dma);
 		dma_free_coherent(cryp->dev, MTK_DESC_RING_SZ,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] cypto: mediatek - fix leaks in mtk_desc_ring_alloc
  2020-09-03  6:38 [PATCH] cypto: mediatek - fix leaks in mtk_desc_ring_alloc Xiaoliang Pang
@ 2020-09-04  7:21 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2020-09-04  7:21 UTC (permalink / raw)
  To: Xiaoliang Pang
  Cc: davem, matthias.bgg, swboyd, yuehaibing, tianjia.zhang,
	ryder.lee, linux-crypto, linux-arm-kernel, linux-mediatek,
	linux-kernel, dawning.pang

Xiaoliang Pang <dawning.pang@gmail.com> wrote:
> In the init loop, if an error occurs in function 'dma_alloc_coherent',
> then goto the err_cleanup section,
> in the cleanup loop, after run i--, 
> the struct mtk_ring rising[i] will not be released,
> causing a memory leak
> 
> Signed-off-by: Xiaoliang Pang <dawning.pang@gmail.com>
> ---
> drivers/crypto/mediatek/mtk-platform.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/crypto/mediatek/mtk-platform.c b/drivers/crypto/mediatek/mtk-platform.c
> index 7e3ad085b5bd..05d341e4a696 100644
> --- a/drivers/crypto/mediatek/mtk-platform.c
> +++ b/drivers/crypto/mediatek/mtk-platform.c
> @@ -469,7 +469,7 @@ static int mtk_desc_ring_alloc(struct mtk_cryp *cryp)
>        return 0;
> 
> err_cleanup:
> -       for (; i--; ) {
> +       for (; i >= 0; --i) {

How about a do while loop instead?

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-04  7:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-03  6:38 [PATCH] cypto: mediatek - fix leaks in mtk_desc_ring_alloc Xiaoliang Pang
2020-09-04  7:21 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).