crypto: ccree - fix resource leak on error path
[ Upstream commit9bc6165d60
] Fix a small resource leak on the error path of cipher processing. Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com> Fixes:63ee04c8b4
("crypto: ccree - add skcipher support") Cc: Markus Elfring <Markus.Elfring@web.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
6a291f9c21
commit
489ee1f219
|
@ -163,7 +163,6 @@ static int cc_cipher_init(struct crypto_tfm *tfm)
|
||||||
skcipher_alg.base);
|
skcipher_alg.base);
|
||||||
struct device *dev = drvdata_to_dev(cc_alg->drvdata);
|
struct device *dev = drvdata_to_dev(cc_alg->drvdata);
|
||||||
unsigned int max_key_buf_size = cc_alg->skcipher_alg.max_keysize;
|
unsigned int max_key_buf_size = cc_alg->skcipher_alg.max_keysize;
|
||||||
int rc = 0;
|
|
||||||
|
|
||||||
dev_dbg(dev, "Initializing context @%p for %s\n", ctx_p,
|
dev_dbg(dev, "Initializing context @%p for %s\n", ctx_p,
|
||||||
crypto_tfm_alg_name(tfm));
|
crypto_tfm_alg_name(tfm));
|
||||||
|
@ -175,10 +174,19 @@ static int cc_cipher_init(struct crypto_tfm *tfm)
|
||||||
ctx_p->flow_mode = cc_alg->flow_mode;
|
ctx_p->flow_mode = cc_alg->flow_mode;
|
||||||
ctx_p->drvdata = cc_alg->drvdata;
|
ctx_p->drvdata = cc_alg->drvdata;
|
||||||
|
|
||||||
|
if (ctx_p->cipher_mode == DRV_CIPHER_ESSIV) {
|
||||||
|
/* Alloc hash tfm for essiv */
|
||||||
|
ctx_p->shash_tfm = crypto_alloc_shash("sha256-generic", 0, 0);
|
||||||
|
if (IS_ERR(ctx_p->shash_tfm)) {
|
||||||
|
dev_err(dev, "Error allocating hash tfm for ESSIV.\n");
|
||||||
|
return PTR_ERR(ctx_p->shash_tfm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Allocate key buffer, cache line aligned */
|
/* Allocate key buffer, cache line aligned */
|
||||||
ctx_p->user.key = kmalloc(max_key_buf_size, GFP_KERNEL);
|
ctx_p->user.key = kmalloc(max_key_buf_size, GFP_KERNEL);
|
||||||
if (!ctx_p->user.key)
|
if (!ctx_p->user.key)
|
||||||
return -ENOMEM;
|
goto free_shash;
|
||||||
|
|
||||||
dev_dbg(dev, "Allocated key buffer in context. key=@%p\n",
|
dev_dbg(dev, "Allocated key buffer in context. key=@%p\n",
|
||||||
ctx_p->user.key);
|
ctx_p->user.key);
|
||||||
|
@ -190,21 +198,19 @@ static int cc_cipher_init(struct crypto_tfm *tfm)
|
||||||
if (dma_mapping_error(dev, ctx_p->user.key_dma_addr)) {
|
if (dma_mapping_error(dev, ctx_p->user.key_dma_addr)) {
|
||||||
dev_err(dev, "Mapping Key %u B at va=%pK for DMA failed\n",
|
dev_err(dev, "Mapping Key %u B at va=%pK for DMA failed\n",
|
||||||
max_key_buf_size, ctx_p->user.key);
|
max_key_buf_size, ctx_p->user.key);
|
||||||
return -ENOMEM;
|
goto free_key;
|
||||||
}
|
}
|
||||||
dev_dbg(dev, "Mapped key %u B at va=%pK to dma=%pad\n",
|
dev_dbg(dev, "Mapped key %u B at va=%pK to dma=%pad\n",
|
||||||
max_key_buf_size, ctx_p->user.key, &ctx_p->user.key_dma_addr);
|
max_key_buf_size, ctx_p->user.key, &ctx_p->user.key_dma_addr);
|
||||||
|
|
||||||
if (ctx_p->cipher_mode == DRV_CIPHER_ESSIV) {
|
return 0;
|
||||||
/* Alloc hash tfm for essiv */
|
|
||||||
ctx_p->shash_tfm = crypto_alloc_shash("sha256-generic", 0, 0);
|
|
||||||
if (IS_ERR(ctx_p->shash_tfm)) {
|
|
||||||
dev_err(dev, "Error allocating hash tfm for ESSIV.\n");
|
|
||||||
return PTR_ERR(ctx_p->shash_tfm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
free_key:
|
||||||
|
kfree(ctx_p->user.key);
|
||||||
|
free_shash:
|
||||||
|
crypto_free_shash(ctx_p->shash_tfm);
|
||||||
|
|
||||||
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cc_cipher_exit(struct crypto_tfm *tfm)
|
static void cc_cipher_exit(struct crypto_tfm *tfm)
|
||||||
|
|
Loading…
Reference in New Issue