Commit 732b7640 authored by Corentin Labbe's avatar Corentin Labbe Committed by Herbert Xu

crypto: sun8i-ce - fix two error path's memory leak

This patch fixes the following smatch warnings:
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c:412
sun8i_ce_hash_run() warn: possible memory leak of 'result'
Note: "buf" is leaked as well.

Furthermore, in case of ENOMEM, crypto_finalize_hash_request() was not
called which was an error.

Fixes: 56f6d5ae ("crypto: sun8i-ce - support hash algorithms")
Reported-by: default avatarkernel test robot <lkp@intel.com>
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarCorentin Labbe <clabbe@baylibre.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 2e0e386a
...@@ -263,13 +263,13 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) ...@@ -263,13 +263,13 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
u32 common; u32 common;
u64 byte_count; u64 byte_count;
__le32 *bf; __le32 *bf;
void *buf; void *buf = NULL;
int j, i, todo; int j, i, todo;
int nbw = 0; int nbw = 0;
u64 fill, min_fill; u64 fill, min_fill;
__be64 *bebits; __be64 *bebits;
__le64 *lebits; __le64 *lebits;
void *result; void *result = NULL;
u64 bs; u64 bs;
int digestsize; int digestsize;
dma_addr_t addr_res, addr_pad; dma_addr_t addr_res, addr_pad;
...@@ -286,13 +286,17 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) ...@@ -286,13 +286,17 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
/* the padding could be up to two block. */ /* the padding could be up to two block. */
buf = kzalloc(bs * 2, GFP_KERNEL | GFP_DMA); buf = kzalloc(bs * 2, GFP_KERNEL | GFP_DMA);
if (!buf) if (!buf) {
return -ENOMEM; err = -ENOMEM;
goto theend;
}
bf = (__le32 *)buf; bf = (__le32 *)buf;
result = kzalloc(digestsize, GFP_KERNEL | GFP_DMA); result = kzalloc(digestsize, GFP_KERNEL | GFP_DMA);
if (!result) if (!result) {
return -ENOMEM; err = -ENOMEM;
goto theend;
}
flow = rctx->flow; flow = rctx->flow;
chan = &ce->chanlist[flow]; chan = &ce->chanlist[flow];
...@@ -404,11 +408,11 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) ...@@ -404,11 +408,11 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_TO_DEVICE); dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_TO_DEVICE);
dma_unmap_single(ce->dev, addr_res, digestsize, DMA_FROM_DEVICE); dma_unmap_single(ce->dev, addr_res, digestsize, DMA_FROM_DEVICE);
kfree(buf);
memcpy(areq->result, result, algt->alg.hash.halg.digestsize); memcpy(areq->result, result, algt->alg.hash.halg.digestsize);
kfree(result);
theend: theend:
kfree(buf);
kfree(result);
crypto_finalize_hash_request(engine, breq, err); crypto_finalize_hash_request(engine, breq, err);
return 0; return 0;
} }
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