* Re: [PATCH 1/3] crypto: ccree: fix resource leak on error path
@ 2020-06-21 9:28 Markus Elfring
0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2020-06-21 9:28 UTC (permalink / raw)
To: Gilad Ben-Yossef, linux-crypto
Cc: linux-kernel, David S. Miller, Herbert Xu, Ofir Drang
> Fix a small resource leak on the error path of cipher processing.
Would you like to add the tag “Fixes” to the commit message?
…
> +++ b/drivers/crypto/ccree/cc_cipher.c
…
> @@ -190,21 +198,19 @@ static int cc_cipher_init(struct crypto_tfm *tfm)
…
> - return rc;
> +out_key:
> + kfree(ctx_p->user.key);
> +out_shash:
> + crypto_free_shash(ctx_p->shash_tfm);
…
How do you think about to replace the prefix “out” by “free” in these labels?
Regards,
Markus
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 0/3] fixes and update to essiv support
@ 2020-06-21 9:07 Gilad Ben-Yossef
2020-06-21 9:07 ` [PATCH 1/3] crypto: ccree: fix resource leak on error path Gilad Ben-Yossef
0 siblings, 1 reply; 2+ messages in thread
From: Gilad Ben-Yossef @ 2020-06-21 9:07 UTC (permalink / raw)
To: Herbert Xu, David S. Miller; +Cc: Ofir Drang, linux-crypto, linux-kernel
Small fixes and adapt essiv support to the new template format
Gilad Ben-Yossef (3):
crypto: ccree: fix resource leak on error path
crypto: ccree: adapt ccree essiv supprot to kcapi
crypto: ccree: remove unused field
drivers/crypto/ccree/cc_cipher.c | 149 ++++++++++++++++++++++---------
1 file changed, 108 insertions(+), 41 deletions(-)
--
2.27.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 1/3] crypto: ccree: fix resource leak on error path
2020-06-21 9:07 [PATCH 0/3] fixes and update to essiv support Gilad Ben-Yossef
@ 2020-06-21 9:07 ` Gilad Ben-Yossef
0 siblings, 0 replies; 2+ messages in thread
From: Gilad Ben-Yossef @ 2020-06-21 9:07 UTC (permalink / raw)
To: Herbert Xu, David S. Miller; +Cc: Ofir Drang, linux-crypto, linux-kernel
Fix a small resource leak on the error path of cipher processing.
Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
---
drivers/crypto/ccree/cc_cipher.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c
index 42ec46be427d..e61f35ca9945 100644
--- a/drivers/crypto/ccree/cc_cipher.c
+++ b/drivers/crypto/ccree/cc_cipher.c
@@ -163,7 +163,6 @@ static int cc_cipher_init(struct crypto_tfm *tfm)
skcipher_alg.base);
struct device *dev = drvdata_to_dev(cc_alg->drvdata);
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,
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->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 */
ctx_p->user.key = kmalloc(max_key_buf_size, GFP_KERNEL);
if (!ctx_p->user.key)
- return -ENOMEM;
+ goto out_shash;
dev_dbg(dev, "Allocated key buffer in context. key=@%p\n",
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)) {
dev_err(dev, "Mapping Key %u B at va=%pK for DMA failed\n",
max_key_buf_size, ctx_p->user.key);
- return -ENOMEM;
+ goto out_key;
}
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);
- 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);
- }
- }
+ return 0;
- return rc;
+out_key:
+ kfree(ctx_p->user.key);
+out_shash:
+ crypto_free_shash(ctx_p->shash_tfm);
+
+ return -ENOMEM;
}
static void cc_cipher_exit(struct crypto_tfm *tfm)
--
2.27.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-21 9:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-21 9:28 [PATCH 1/3] crypto: ccree: fix resource leak on error path Markus Elfring
-- strict thread matches above, loose matches on Subject: below --
2020-06-21 9:07 [PATCH 0/3] fixes and update to essiv support Gilad Ben-Yossef
2020-06-21 9:07 ` [PATCH 1/3] crypto: ccree: fix resource leak on error path Gilad Ben-Yossef
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®