diff mbox series

[next] crypto: sun8i-ss: Fix memory leak of pad

Message ID 20210401151827.2015960-1-colin.king@canonical.com
State Accepted
Commit 50274b01ac1689b1a3f6bc4b5b3dbf361a55dd3a
Headers show
Series [next] crypto: sun8i-ss: Fix memory leak of pad | expand

Commit Message

Colin King April 1, 2021, 3:18 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

It appears there are several failure return paths that don't seem
to be free'ing pad. Fix these.

Addresses-Coverity: ("Resource leak")
Fixes: d9b45418a917 ("crypto: sun8i-ss - support hash algorithms")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Corentin Labbe April 2, 2021, 11:18 a.m. UTC | #1
Le Thu, Apr 01, 2021 at 04:18:27PM +0100, Colin King a écrit :
> From: Colin Ian King <colin.king@canonical.com>

> 

> It appears there are several failure return paths that don't seem

> to be free'ing pad. Fix these.

> 

> Addresses-Coverity: ("Resource leak")

> Fixes: d9b45418a917 ("crypto: sun8i-ss - support hash algorithms")

> Signed-off-by: Colin Ian King <colin.king@canonical.com>

> ---


Hello

Acked-by: Corentin Labbe <clabbe.montjoie@gmail.com>

Tested-by: Corentin Labbe <clabbe.montjoie@gmail.com>

Tested-on: sun8i-a83t-bananapi-m3

Thanks
Herbert Xu April 9, 2021, 7:54 a.m. UTC | #2
On Thu, Apr 01, 2021 at 04:18:27PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>

> 

> It appears there are several failure return paths that don't seem

> to be free'ing pad. Fix these.

> 

> Addresses-Coverity: ("Resource leak")

> Fixes: d9b45418a917 ("crypto: sun8i-ss - support hash algorithms")

> Signed-off-by: Colin Ian King <colin.king@canonical.com>

> ---

>  drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 7 ++++---

>  1 file changed, 4 insertions(+), 3 deletions(-)


Patch applied.  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
diff mbox series

Patch

diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
index 7d1fc9aba665..3c073eb3db03 100644
--- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
+++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
@@ -348,8 +348,10 @@  int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq)
 	bf = (__le32 *)pad;
 
 	result = kzalloc(digestsize, GFP_KERNEL | GFP_DMA);
-	if (!result)
+	if (!result) {
+		kfree(pad);
 		return -ENOMEM;
+	}
 
 	for (i = 0; i < MAX_SG; i++) {
 		rctx->t_dst[i].addr = 0;
@@ -436,10 +438,9 @@  int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq)
 		     DMA_TO_DEVICE);
 	dma_unmap_single(ss->dev, addr_res, digestsize, DMA_FROM_DEVICE);
 
-	kfree(pad);
-
 	memcpy(areq->result, result, algt->alg.hash.halg.digestsize);
 theend:
+	kfree(pad);
 	kfree(result);
 	crypto_finalize_hash_request(engine, breq, err);
 	return 0;