Skip to content

Commit

Permalink
crypto: sun8i-ss - Fix memory leak of pad
Browse files Browse the repository at this point in the history
It appears there are several failure return paths that don't seem
to be free'ing pad. Fix these.

Addresses-Coverity: ("Resource leak")
Fixes: d9b4541 ("crypto: sun8i-ss - support hash algorithms")
Signed-off-by: Colin Ian King <[email protected]>
Acked-by: Corentin Labbe <[email protected]>
Tested-by: Corentin Labbe <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
Colin Ian King authored and herbertx committed Apr 9, 2021
1 parent 3d8c5f5 commit 50274b0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 50274b0

Please sign in to comment.