From: Horia Geanta Date: Fri, 18 Apr 2014 10:01:41 +0000 (+0300) Subject: crypto: caam - fix mem leak in ahash_setkey X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=3d67be2761dc4b5b792037f296f3394a29581efc;p=linux-beck.git crypto: caam - fix mem leak in ahash_setkey In case hash key is bigger than algorithm block size, it is hashed. In this case, memory is allocated to keep this hash in hashed_key. hashed_key has to be freed on the key_dma dma mapping error path. Signed-off-by: Horia Geanta Reviewed-by: Marek Vasut Signed-off-by: Herbert Xu --- diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index 0378328f47a7..2d244e629ed2 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c @@ -545,7 +545,8 @@ static int ahash_setkey(struct crypto_ahash *ahash, DMA_TO_DEVICE); if (dma_mapping_error(jrdev, ctx->key_dma)) { dev_err(jrdev, "unable to map key i/o memory\n"); - return -ENOMEM; + ret = -ENOMEM; + goto map_err; } #ifdef DEBUG print_hex_dump(KERN_ERR, "ctx.key@"__stringify(__LINE__)": ", @@ -559,6 +560,7 @@ static int ahash_setkey(struct crypto_ahash *ahash, DMA_TO_DEVICE); } +map_err: kfree(hashed_key); return ret; badkey: