Commit 56601574 authored by Corentin Labbe's avatar Corentin Labbe Committed by Herbert Xu

crypto: amlogic - fix two resources leak

This patch fixes two resources leak that occur on error path.
Reported-by: default avatarcoverity-bot <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1487403 ("RESOURCE_LEAK")
Addresses-Coverity-ID: 1487401 ("Resource leaks")
Fixes: 48fe583f ("crypto: amlogic - Add crypto accelerator for amlogic GXL")
Signed-off-by: default avatarCorentin Labbe <clabbe@baylibre.com>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent b8151220
...@@ -131,7 +131,8 @@ static int meson_cipher(struct skcipher_request *areq) ...@@ -131,7 +131,8 @@ static int meson_cipher(struct skcipher_request *areq)
if (areq->iv && ivsize > 0) { if (areq->iv && ivsize > 0) {
if (ivsize > areq->cryptlen) { if (ivsize > areq->cryptlen) {
dev_err(mc->dev, "invalid ivsize=%d vs len=%d\n", ivsize, areq->cryptlen); dev_err(mc->dev, "invalid ivsize=%d vs len=%d\n", ivsize, areq->cryptlen);
return -EINVAL; err = -EINVAL;
goto theend;
} }
memcpy(bkeyiv + 32, areq->iv, ivsize); memcpy(bkeyiv + 32, areq->iv, ivsize);
keyivlen = 48; keyivlen = 48;
...@@ -151,9 +152,10 @@ static int meson_cipher(struct skcipher_request *areq) ...@@ -151,9 +152,10 @@ static int meson_cipher(struct skcipher_request *areq)
phykeyiv = dma_map_single(mc->dev, bkeyiv, keyivlen, phykeyiv = dma_map_single(mc->dev, bkeyiv, keyivlen,
DMA_TO_DEVICE); DMA_TO_DEVICE);
if (dma_mapping_error(mc->dev, phykeyiv)) { err = dma_mapping_error(mc->dev, phykeyiv);
if (err) {
dev_err(mc->dev, "Cannot DMA MAP KEY IV\n"); dev_err(mc->dev, "Cannot DMA MAP KEY IV\n");
return -EFAULT; goto theend;
} }
tloffset = 0; tloffset = 0;
...@@ -245,7 +247,6 @@ static int meson_cipher(struct skcipher_request *areq) ...@@ -245,7 +247,6 @@ static int meson_cipher(struct skcipher_request *areq)
if (areq->iv && ivsize > 0) { if (areq->iv && ivsize > 0) {
if (rctx->op_dir == MESON_DECRYPT) { if (rctx->op_dir == MESON_DECRYPT) {
memcpy(areq->iv, backup_iv, ivsize); memcpy(areq->iv, backup_iv, ivsize);
kzfree(backup_iv);
} else { } else {
scatterwalk_map_and_copy(areq->iv, areq->dst, scatterwalk_map_and_copy(areq->iv, areq->dst,
areq->cryptlen - ivsize, areq->cryptlen - ivsize,
...@@ -254,6 +255,7 @@ static int meson_cipher(struct skcipher_request *areq) ...@@ -254,6 +255,7 @@ static int meson_cipher(struct skcipher_request *areq)
} }
theend: theend:
kzfree(bkeyiv); kzfree(bkeyiv);
kzfree(backup_iv);
return err; return err;
} }
......
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