crypto: sun8i-ss - Fix memory leak of pad
authorColin Ian King <colin.king@canonical.com>
Thu, 1 Apr 2021 15:18:27 +0000 (16:18 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 14 May 2021 07:50:17 +0000 (09:50 +0200)
[ Upstream commit 50274b01ac1689b1a3f6bc4b5b3dbf361a55dd3a ]

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>
Acked-by: Corentin Labbe <clabbe.montjoie@gmail.com>
Tested-by: Corentin Labbe <clabbe.montjoie@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c

index 541bcd8..756d5a7 100644 (file)
@@ -347,8 +347,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;
@@ -434,10 +436,9 @@ int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq)
        dma_unmap_sg(ss->dev, areq->src, nr_sgs, 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;