* [PATCH 00/12] crypto: more template instantiation cleanups
@ 2020-02-26 4:59 Eric Biggers
2020-02-26 4:59 ` [PATCH 01/12] crypto: authencesn - fix weird comma-terminated line Eric Biggers
` (12 more replies)
0 siblings, 13 replies; 14+ messages in thread
From: Eric Biggers @ 2020-02-26 4:59 UTC (permalink / raw)
To: linux-crypto
This series simplifies error handling in the remaining crypto templates,
taking advantage of the changes I made last release that made
crypto_grab_*() accept ERR_PTR() names and crypto_drop_*() accept
spawns that haven't been grabbed yet:
https://lore.kernel.org/r/20200103035908.12048-1-ebiggers@kernel.org
Many templates were already converted to the new style by that series.
This series just handles the remainder.
This series is an internal cleanup only; there are no changes for users
of the crypto API. Net change is 124 lines of code removed.
Eric Biggers (12):
crypto: authencesn - fix weird comma-terminated line
crypto: ccm - simplify error handling in crypto_rfc4309_create()
crypto: cryptd - simplify error handling in cryptd_create_*()
crypto: ctr - simplify error handling in crypto_rfc3686_create()
crypto: cts - simplify error handling in crypto_cts_create()
crypto: gcm - simplify error handling in crypto_rfc4106_create()
crypto: gcm - simplify error handling in crypto_rfc4543_create()
crypto: geniv - simply error handling in aead_geniv_alloc()
crypto: lrw - simplify error handling in create()
crypto: pcrypt - simplify error handling in pcrypt_create_aead()
crypto: rsa-pkcs1pad - simplify error handling in pkcs1pad_create()
crypto: xts - simplify error handling in ->create()
crypto/authencesn.c | 2 +-
crypto/ccm.c | 29 ++++++-------------
crypto/cryptd.c | 37 ++++++++----------------
crypto/ctr.c | 29 ++++++-------------
crypto/cts.c | 27 ++++++------------
crypto/gcm.c | 66 ++++++++++++++-----------------------------
crypto/geniv.c | 17 ++++-------
crypto/lrw.c | 28 ++++++++----------
crypto/pcrypt.c | 33 ++++++----------------
crypto/rsa-pkcs1pad.c | 59 +++++++++++++-------------------------
crypto/xts.c | 28 ++++++++----------
kernel/padata.c | 7 +++--
12 files changed, 119 insertions(+), 243 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 01/12] crypto: authencesn - fix weird comma-terminated line
2020-02-26 4:59 [PATCH 00/12] crypto: more template instantiation cleanups Eric Biggers
@ 2020-02-26 4:59 ` Eric Biggers
2020-02-26 4:59 ` [PATCH 02/12] crypto: ccm - simplify error handling in crypto_rfc4309_create() Eric Biggers
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Eric Biggers @ 2020-02-26 4:59 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
Fix a weird case where a line was terminated by a comma rather than a
semicolon, causing the statement to be continued on the next line.
Fortunately the code still behaved as intended, though.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/authencesn.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/crypto/authencesn.c b/crypto/authencesn.c
index 589008146fce7..149b70df2a917 100644
--- a/crypto/authencesn.c
+++ b/crypto/authencesn.c
@@ -458,7 +458,7 @@ static int crypto_authenc_esn_create(struct crypto_template *tmpl,
inst->alg.encrypt = crypto_authenc_esn_encrypt;
inst->alg.decrypt = crypto_authenc_esn_decrypt;
- inst->free = crypto_authenc_esn_free,
+ inst->free = crypto_authenc_esn_free;
err = aead_register_instance(tmpl, inst);
if (err) {
base-commit: ff462ddfd95b915345c3c7c037c3bfafdc58bae7
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 02/12] crypto: ccm - simplify error handling in crypto_rfc4309_create()
2020-02-26 4:59 [PATCH 00/12] crypto: more template instantiation cleanups Eric Biggers
2020-02-26 4:59 ` [PATCH 01/12] crypto: authencesn - fix weird comma-terminated line Eric Biggers
@ 2020-02-26 4:59 ` Eric Biggers
2020-02-26 4:59 ` [PATCH 03/12] crypto: cryptd - simplify error handling in cryptd_create_*() Eric Biggers
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Eric Biggers @ 2020-02-26 4:59 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
Simplify the error handling in crypto_rfc4309_create() by taking
advantage of crypto_grab_aead() now handling an ERR_PTR() name and by
taking advantage of crypto_drop_aead() now accepting (as a no-op) a
spawn that hasn't been grabbed yet.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/ccm.c | 29 +++++++++--------------------
1 file changed, 9 insertions(+), 20 deletions(-)
diff --git a/crypto/ccm.c b/crypto/ccm.c
index 241ecdc5c4e0e..d1fb01bbc8143 100644
--- a/crypto/ccm.c
+++ b/crypto/ccm.c
@@ -717,7 +717,6 @@ static int crypto_rfc4309_create(struct crypto_template *tmpl,
struct aead_instance *inst;
struct crypto_aead_spawn *spawn;
struct aead_alg *alg;
- const char *ccm_name;
int err;
algt = crypto_get_attr_type(tb);
@@ -729,19 +728,15 @@ static int crypto_rfc4309_create(struct crypto_template *tmpl,
mask = crypto_requires_sync(algt->type, algt->mask);
- ccm_name = crypto_attr_alg_name(tb[1]);
- if (IS_ERR(ccm_name))
- return PTR_ERR(ccm_name);
-
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
if (!inst)
return -ENOMEM;
spawn = aead_instance_ctx(inst);
err = crypto_grab_aead(spawn, aead_crypto_instance(inst),
- ccm_name, 0, mask);
+ crypto_attr_alg_name(tb[1]), 0, mask);
if (err)
- goto out_free_inst;
+ goto err_free_inst;
alg = crypto_spawn_aead_alg(spawn);
@@ -749,11 +744,11 @@ static int crypto_rfc4309_create(struct crypto_template *tmpl,
/* We only support 16-byte blocks. */
if (crypto_aead_alg_ivsize(alg) != 16)
- goto out_drop_alg;
+ goto err_free_inst;
/* Not a stream cipher? */
if (alg->base.cra_blocksize != 1)
- goto out_drop_alg;
+ goto err_free_inst;
err = -ENAMETOOLONG;
if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME,
@@ -762,7 +757,7 @@ static int crypto_rfc4309_create(struct crypto_template *tmpl,
snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME,
"rfc4309(%s)", alg->base.cra_driver_name) >=
CRYPTO_MAX_ALG_NAME)
- goto out_drop_alg;
+ goto err_free_inst;
inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC;
inst->alg.base.cra_priority = alg->base.cra_priority;
@@ -786,17 +781,11 @@ static int crypto_rfc4309_create(struct crypto_template *tmpl,
inst->free = crypto_rfc4309_free;
err = aead_register_instance(tmpl, inst);
- if (err)
- goto out_drop_alg;
-
-out:
+ if (err) {
+err_free_inst:
+ crypto_rfc4309_free(inst);
+ }
return err;
-
-out_drop_alg:
- crypto_drop_aead(spawn);
-out_free_inst:
- kfree(inst);
- goto out;
}
static int crypto_cbcmac_digest_setkey(struct crypto_shash *parent,
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 03/12] crypto: cryptd - simplify error handling in cryptd_create_*()
2020-02-26 4:59 [PATCH 00/12] crypto: more template instantiation cleanups Eric Biggers
2020-02-26 4:59 ` [PATCH 01/12] crypto: authencesn - fix weird comma-terminated line Eric Biggers
2020-02-26 4:59 ` [PATCH 02/12] crypto: ccm - simplify error handling in crypto_rfc4309_create() Eric Biggers
@ 2020-02-26 4:59 ` Eric Biggers
2020-02-26 4:59 ` [PATCH 04/12] crypto: ctr - simplify error handling in crypto_rfc3686_create() Eric Biggers
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Eric Biggers @ 2020-02-26 4:59 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
Simplify the error handling in the various cryptd_create_*() functions
by taking advantage of crypto_grab_*() now handling an ERR_PTR() name
and by taking advantage of crypto_drop_*() now accepting (as a no-op) a
spawn that hasn't been grabbed yet.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/cryptd.c | 37 +++++++++++--------------------------
1 file changed, 11 insertions(+), 26 deletions(-)
diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index d94c75c840a5e..283212262adbb 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -369,7 +369,6 @@ static int cryptd_create_skcipher(struct crypto_template *tmpl,
struct skcipherd_instance_ctx *ctx;
struct skcipher_instance *inst;
struct skcipher_alg *alg;
- const char *name;
u32 type;
u32 mask;
int err;
@@ -379,10 +378,6 @@ static int cryptd_create_skcipher(struct crypto_template *tmpl,
cryptd_check_internal(tb, &type, &mask);
- name = crypto_attr_alg_name(tb[1]);
- if (IS_ERR(name))
- return PTR_ERR(name);
-
inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
if (!inst)
return -ENOMEM;
@@ -391,14 +386,14 @@ static int cryptd_create_skcipher(struct crypto_template *tmpl,
ctx->queue = queue;
err = crypto_grab_skcipher(&ctx->spawn, skcipher_crypto_instance(inst),
- name, type, mask);
+ crypto_attr_alg_name(tb[1]), type, mask);
if (err)
- goto out_free_inst;
+ goto err_free_inst;
alg = crypto_spawn_skcipher_alg(&ctx->spawn);
err = cryptd_init_instance(skcipher_crypto_instance(inst), &alg->base);
if (err)
- goto out_drop_skcipher;
+ goto err_free_inst;
inst->alg.base.cra_flags = CRYPTO_ALG_ASYNC |
(alg->base.cra_flags & CRYPTO_ALG_INTERNAL);
@@ -421,10 +416,8 @@ static int cryptd_create_skcipher(struct crypto_template *tmpl,
err = skcipher_register_instance(tmpl, inst);
if (err) {
-out_drop_skcipher:
- crypto_drop_skcipher(&ctx->spawn);
-out_free_inst:
- kfree(inst);
+err_free_inst:
+ cryptd_skcipher_free(inst);
}
return err;
}
@@ -694,8 +687,7 @@ static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb,
err = ahash_register_instance(tmpl, inst);
if (err) {
err_free_inst:
- crypto_drop_shash(&ctx->spawn);
- kfree(inst);
+ cryptd_hash_free(inst);
}
return err;
}
@@ -833,17 +825,12 @@ static int cryptd_create_aead(struct crypto_template *tmpl,
struct aead_instance_ctx *ctx;
struct aead_instance *inst;
struct aead_alg *alg;
- const char *name;
u32 type = 0;
u32 mask = CRYPTO_ALG_ASYNC;
int err;
cryptd_check_internal(tb, &type, &mask);
- name = crypto_attr_alg_name(tb[1]);
- if (IS_ERR(name))
- return PTR_ERR(name);
-
inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
if (!inst)
return -ENOMEM;
@@ -852,14 +839,14 @@ static int cryptd_create_aead(struct crypto_template *tmpl,
ctx->queue = queue;
err = crypto_grab_aead(&ctx->aead_spawn, aead_crypto_instance(inst),
- name, type, mask);
+ crypto_attr_alg_name(tb[1]), type, mask);
if (err)
- goto out_free_inst;
+ goto err_free_inst;
alg = crypto_spawn_aead_alg(&ctx->aead_spawn);
err = cryptd_init_instance(aead_crypto_instance(inst), &alg->base);
if (err)
- goto out_drop_aead;
+ goto err_free_inst;
inst->alg.base.cra_flags = CRYPTO_ALG_ASYNC |
(alg->base.cra_flags & CRYPTO_ALG_INTERNAL);
@@ -879,10 +866,8 @@ static int cryptd_create_aead(struct crypto_template *tmpl,
err = aead_register_instance(tmpl, inst);
if (err) {
-out_drop_aead:
- crypto_drop_aead(&ctx->aead_spawn);
-out_free_inst:
- kfree(inst);
+err_free_inst:
+ cryptd_aead_free(inst);
}
return err;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 04/12] crypto: ctr - simplify error handling in crypto_rfc3686_create()
2020-02-26 4:59 [PATCH 00/12] crypto: more template instantiation cleanups Eric Biggers
` (2 preceding siblings ...)
2020-02-26 4:59 ` [PATCH 03/12] crypto: cryptd - simplify error handling in cryptd_create_*() Eric Biggers
@ 2020-02-26 4:59 ` Eric Biggers
2020-02-26 4:59 ` [PATCH 05/12] crypto: cts - simplify error handling in crypto_cts_create() Eric Biggers
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Eric Biggers @ 2020-02-26 4:59 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
Simplify the error handling in crypto_rfc3686_create() by taking
advantage of crypto_grab_skcipher() now handling an ERR_PTR() name and
by taking advantage of crypto_drop_skcipher() now accepting (as a no-op)
a spawn that hasn't been grabbed yet.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/ctr.c | 29 +++++++++--------------------
1 file changed, 9 insertions(+), 20 deletions(-)
diff --git a/crypto/ctr.c b/crypto/ctr.c
index a8feab621c6c1..31ac4ae598e17 100644
--- a/crypto/ctr.c
+++ b/crypto/ctr.c
@@ -260,7 +260,6 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl,
struct skcipher_instance *inst;
struct skcipher_alg *alg;
struct crypto_skcipher_spawn *spawn;
- const char *cipher_name;
u32 mask;
int err;
@@ -272,10 +271,6 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl,
if ((algt->type ^ CRYPTO_ALG_TYPE_SKCIPHER) & algt->mask)
return -EINVAL;
- cipher_name = crypto_attr_alg_name(tb[1]);
- if (IS_ERR(cipher_name))
- return PTR_ERR(cipher_name);
-
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
if (!inst)
return -ENOMEM;
@@ -287,7 +282,7 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl,
spawn = skcipher_instance_ctx(inst);
err = crypto_grab_skcipher(spawn, skcipher_crypto_instance(inst),
- cipher_name, 0, mask);
+ crypto_attr_alg_name(tb[1]), 0, mask);
if (err)
goto err_free_inst;
@@ -296,20 +291,20 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl,
/* We only support 16-byte blocks. */
err = -EINVAL;
if (crypto_skcipher_alg_ivsize(alg) != CTR_RFC3686_BLOCK_SIZE)
- goto err_drop_spawn;
+ goto err_free_inst;
/* Not a stream cipher? */
if (alg->base.cra_blocksize != 1)
- goto err_drop_spawn;
+ goto err_free_inst;
err = -ENAMETOOLONG;
if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME,
"rfc3686(%s)", alg->base.cra_name) >= CRYPTO_MAX_ALG_NAME)
- goto err_drop_spawn;
+ goto err_free_inst;
if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME,
"rfc3686(%s)", alg->base.cra_driver_name) >=
CRYPTO_MAX_ALG_NAME)
- goto err_drop_spawn;
+ goto err_free_inst;
inst->alg.base.cra_priority = alg->base.cra_priority;
inst->alg.base.cra_blocksize = 1;
@@ -336,17 +331,11 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl,
inst->free = crypto_rfc3686_free;
err = skcipher_register_instance(tmpl, inst);
- if (err)
- goto err_drop_spawn;
-
-out:
- return err;
-
-err_drop_spawn:
- crypto_drop_skcipher(spawn);
+ if (err) {
err_free_inst:
- kfree(inst);
- goto out;
+ crypto_rfc3686_free(inst);
+ }
+ return err;
}
static struct crypto_template crypto_ctr_tmpls[] = {
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 05/12] crypto: cts - simplify error handling in crypto_cts_create()
2020-02-26 4:59 [PATCH 00/12] crypto: more template instantiation cleanups Eric Biggers
` (3 preceding siblings ...)
2020-02-26 4:59 ` [PATCH 04/12] crypto: ctr - simplify error handling in crypto_rfc3686_create() Eric Biggers
@ 2020-02-26 4:59 ` Eric Biggers
2020-02-26 4:59 ` [PATCH 06/12] crypto: gcm - simplify error handling in crypto_rfc4106_create() Eric Biggers
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Eric Biggers @ 2020-02-26 4:59 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
Simplify the error handling in crypto_cts_create() by taking advantage
of crypto_grab_skcipher() now handling an ERR_PTR() name and by taking
advantage of crypto_drop_skcipher() now accepting (as a no-op) a spawn
that hasn't been grabbed yet.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/cts.c | 27 ++++++++-------------------
1 file changed, 8 insertions(+), 19 deletions(-)
diff --git a/crypto/cts.c b/crypto/cts.c
index 48188adc8e91c..5e005c4f02215 100644
--- a/crypto/cts.c
+++ b/crypto/cts.c
@@ -327,7 +327,6 @@ static int crypto_cts_create(struct crypto_template *tmpl, struct rtattr **tb)
struct skcipher_instance *inst;
struct crypto_attr_type *algt;
struct skcipher_alg *alg;
- const char *cipher_name;
u32 mask;
int err;
@@ -340,10 +339,6 @@ static int crypto_cts_create(struct crypto_template *tmpl, struct rtattr **tb)
mask = crypto_requires_sync(algt->type, algt->mask);
- cipher_name = crypto_attr_alg_name(tb[1]);
- if (IS_ERR(cipher_name))
- return PTR_ERR(cipher_name);
-
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
if (!inst)
return -ENOMEM;
@@ -351,7 +346,7 @@ static int crypto_cts_create(struct crypto_template *tmpl, struct rtattr **tb)
spawn = skcipher_instance_ctx(inst);
err = crypto_grab_skcipher(spawn, skcipher_crypto_instance(inst),
- cipher_name, 0, mask);
+ crypto_attr_alg_name(tb[1]), 0, mask);
if (err)
goto err_free_inst;
@@ -359,15 +354,15 @@ static int crypto_cts_create(struct crypto_template *tmpl, struct rtattr **tb)
err = -EINVAL;
if (crypto_skcipher_alg_ivsize(alg) != alg->base.cra_blocksize)
- goto err_drop_spawn;
+ goto err_free_inst;
if (strncmp(alg->base.cra_name, "cbc(", 4))
- goto err_drop_spawn;
+ goto err_free_inst;
err = crypto_inst_setname(skcipher_crypto_instance(inst), "cts",
&alg->base);
if (err)
- goto err_drop_spawn;
+ goto err_free_inst;
inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC;
inst->alg.base.cra_priority = alg->base.cra_priority;
@@ -391,17 +386,11 @@ static int crypto_cts_create(struct crypto_template *tmpl, struct rtattr **tb)
inst->free = crypto_cts_free;
err = skcipher_register_instance(tmpl, inst);
- if (err)
- goto err_drop_spawn;
-
-out:
- return err;
-
-err_drop_spawn:
- crypto_drop_skcipher(spawn);
+ if (err) {
err_free_inst:
- kfree(inst);
- goto out;
+ crypto_cts_free(inst);
+ }
+ return err;
}
static struct crypto_template crypto_cts_tmpl = {
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 06/12] crypto: gcm - simplify error handling in crypto_rfc4106_create()
2020-02-26 4:59 [PATCH 00/12] crypto: more template instantiation cleanups Eric Biggers
` (4 preceding siblings ...)
2020-02-26 4:59 ` [PATCH 05/12] crypto: cts - simplify error handling in crypto_cts_create() Eric Biggers
@ 2020-02-26 4:59 ` Eric Biggers
2020-02-26 4:59 ` [PATCH 07/12] crypto: gcm - simplify error handling in crypto_rfc4543_create() Eric Biggers
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Eric Biggers @ 2020-02-26 4:59 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
Simplify the error handling in crypto_rfc4106_create() by taking
advantage of crypto_grab_aead() now handling an ERR_PTR() name and by
taking advantage of crypto_drop_aead() now accepting (as a no-op) a
spawn that hasn't been grabbed yet.
Conveniently, this eliminates the 'ccm_name' variable which was
incorrectly named (it should have been 'gcm_name').
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/gcm.c | 29 +++++++++--------------------
1 file changed, 9 insertions(+), 20 deletions(-)
diff --git a/crypto/gcm.c b/crypto/gcm.c
index 8e5c0ac656611..5560341e28105 100644
--- a/crypto/gcm.c
+++ b/crypto/gcm.c
@@ -840,7 +840,6 @@ static int crypto_rfc4106_create(struct crypto_template *tmpl,
struct aead_instance *inst;
struct crypto_aead_spawn *spawn;
struct aead_alg *alg;
- const char *ccm_name;
int err;
algt = crypto_get_attr_type(tb);
@@ -852,19 +851,15 @@ static int crypto_rfc4106_create(struct crypto_template *tmpl,
mask = crypto_requires_sync(algt->type, algt->mask);
- ccm_name = crypto_attr_alg_name(tb[1]);
- if (IS_ERR(ccm_name))
- return PTR_ERR(ccm_name);
-
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
if (!inst)
return -ENOMEM;
spawn = aead_instance_ctx(inst);
err = crypto_grab_aead(spawn, aead_crypto_instance(inst),
- ccm_name, 0, mask);
+ crypto_attr_alg_name(tb[1]), 0, mask);
if (err)
- goto out_free_inst;
+ goto err_free_inst;
alg = crypto_spawn_aead_alg(spawn);
@@ -872,11 +867,11 @@ static int crypto_rfc4106_create(struct crypto_template *tmpl,
/* Underlying IV size must be 12. */
if (crypto_aead_alg_ivsize(alg) != GCM_AES_IV_SIZE)
- goto out_drop_alg;
+ goto err_free_inst;
/* Not a stream cipher? */
if (alg->base.cra_blocksize != 1)
- goto out_drop_alg;
+ goto err_free_inst;
err = -ENAMETOOLONG;
if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME,
@@ -885,7 +880,7 @@ static int crypto_rfc4106_create(struct crypto_template *tmpl,
snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME,
"rfc4106(%s)", alg->base.cra_driver_name) >=
CRYPTO_MAX_ALG_NAME)
- goto out_drop_alg;
+ goto err_free_inst;
inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC;
inst->alg.base.cra_priority = alg->base.cra_priority;
@@ -909,17 +904,11 @@ static int crypto_rfc4106_create(struct crypto_template *tmpl,
inst->free = crypto_rfc4106_free;
err = aead_register_instance(tmpl, inst);
- if (err)
- goto out_drop_alg;
-
-out:
+ if (err) {
+err_free_inst:
+ crypto_rfc4106_free(inst);
+ }
return err;
-
-out_drop_alg:
- crypto_drop_aead(spawn);
-out_free_inst:
- kfree(inst);
- goto out;
}
static int crypto_rfc4543_setkey(struct crypto_aead *parent, const u8 *key,
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 07/12] crypto: gcm - simplify error handling in crypto_rfc4543_create()
2020-02-26 4:59 [PATCH 00/12] crypto: more template instantiation cleanups Eric Biggers
` (5 preceding siblings ...)
2020-02-26 4:59 ` [PATCH 06/12] crypto: gcm - simplify error handling in crypto_rfc4106_create() Eric Biggers
@ 2020-02-26 4:59 ` Eric Biggers
2020-02-26 4:59 ` [PATCH 08/12] crypto: geniv - simply error handling in aead_geniv_alloc() Eric Biggers
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Eric Biggers @ 2020-02-26 4:59 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
Simplify the error handling in crypto_rfc4543_create() by taking
advantage of crypto_grab_aead() now handling an ERR_PTR() name and by
taking advantage of crypto_drop_aead() now accepting (as a no-op) a
spawn that hasn't been grabbed yet.
Conveniently, this eliminates the 'ccm_name' variable which was
incorrectly named (it should have been 'gcm_name').
Also fix a weird case where a line was terminated by a comma rather than
a semicolon, causing the statement to be continued on the next line.
Fortunately the code still behaved as intended, though.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/gcm.c | 37 ++++++++++++-------------------------
1 file changed, 12 insertions(+), 25 deletions(-)
diff --git a/crypto/gcm.c b/crypto/gcm.c
index 5560341e28105..0103d28c541eb 100644
--- a/crypto/gcm.c
+++ b/crypto/gcm.c
@@ -1060,10 +1060,8 @@ static int crypto_rfc4543_create(struct crypto_template *tmpl,
struct crypto_attr_type *algt;
u32 mask;
struct aead_instance *inst;
- struct crypto_aead_spawn *spawn;
struct aead_alg *alg;
struct crypto_rfc4543_instance_ctx *ctx;
- const char *ccm_name;
int err;
algt = crypto_get_attr_type(tb);
@@ -1075,32 +1073,27 @@ static int crypto_rfc4543_create(struct crypto_template *tmpl,
mask = crypto_requires_sync(algt->type, algt->mask);
- ccm_name = crypto_attr_alg_name(tb[1]);
- if (IS_ERR(ccm_name))
- return PTR_ERR(ccm_name);
-
inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
if (!inst)
return -ENOMEM;
ctx = aead_instance_ctx(inst);
- spawn = &ctx->aead;
- err = crypto_grab_aead(spawn, aead_crypto_instance(inst),
- ccm_name, 0, mask);
+ err = crypto_grab_aead(&ctx->aead, aead_crypto_instance(inst),
+ crypto_attr_alg_name(tb[1]), 0, mask);
if (err)
- goto out_free_inst;
+ goto err_free_inst;
- alg = crypto_spawn_aead_alg(spawn);
+ alg = crypto_spawn_aead_alg(&ctx->aead);
err = -EINVAL;
/* Underlying IV size must be 12. */
if (crypto_aead_alg_ivsize(alg) != GCM_AES_IV_SIZE)
- goto out_drop_alg;
+ goto err_free_inst;
/* Not a stream cipher? */
if (alg->base.cra_blocksize != 1)
- goto out_drop_alg;
+ goto err_free_inst;
err = -ENAMETOOLONG;
if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME,
@@ -1109,7 +1102,7 @@ static int crypto_rfc4543_create(struct crypto_template *tmpl,
snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME,
"rfc4543(%s)", alg->base.cra_driver_name) >=
CRYPTO_MAX_ALG_NAME)
- goto out_drop_alg;
+ goto err_free_inst;
inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC;
inst->alg.base.cra_priority = alg->base.cra_priority;
@@ -1130,20 +1123,14 @@ static int crypto_rfc4543_create(struct crypto_template *tmpl,
inst->alg.encrypt = crypto_rfc4543_encrypt;
inst->alg.decrypt = crypto_rfc4543_decrypt;
- inst->free = crypto_rfc4543_free,
+ inst->free = crypto_rfc4543_free;
err = aead_register_instance(tmpl, inst);
- if (err)
- goto out_drop_alg;
-
-out:
+ if (err) {
+err_free_inst:
+ crypto_rfc4543_free(inst);
+ }
return err;
-
-out_drop_alg:
- crypto_drop_aead(spawn);
-out_free_inst:
- kfree(inst);
- goto out;
}
static struct crypto_template crypto_gcm_tmpls[] = {
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 08/12] crypto: geniv - simply error handling in aead_geniv_alloc()
2020-02-26 4:59 [PATCH 00/12] crypto: more template instantiation cleanups Eric Biggers
` (6 preceding siblings ...)
2020-02-26 4:59 ` [PATCH 07/12] crypto: gcm - simplify error handling in crypto_rfc4543_create() Eric Biggers
@ 2020-02-26 4:59 ` Eric Biggers
2020-02-26 4:59 ` [PATCH 09/12] crypto: lrw - simplify error handling in create() Eric Biggers
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Eric Biggers @ 2020-02-26 4:59 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
Simplify the error handling in aead_geniv_alloc() by taking advantage of
crypto_grab_aead() now handling an ERR_PTR() name and by taking
advantage of crypto_drop_aead() now accepting (as a no-op) a spawn that
hasn't been grabbed yet.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/geniv.c | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/crypto/geniv.c b/crypto/geniv.c
index dbcc640274cda..6a90c52d49ad1 100644
--- a/crypto/geniv.c
+++ b/crypto/geniv.c
@@ -41,7 +41,6 @@ static void aead_geniv_free(struct aead_instance *inst)
struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
struct rtattr **tb, u32 type, u32 mask)
{
- const char *name;
struct crypto_aead_spawn *spawn;
struct crypto_attr_type *algt;
struct aead_instance *inst;
@@ -57,10 +56,6 @@ struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
return ERR_PTR(-EINVAL);
- name = crypto_attr_alg_name(tb[1]);
- if (IS_ERR(name))
- return ERR_CAST(name);
-
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
if (!inst)
return ERR_PTR(-ENOMEM);
@@ -71,7 +66,7 @@ struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
mask |= crypto_requires_sync(algt->type, algt->mask);
err = crypto_grab_aead(spawn, aead_crypto_instance(inst),
- name, type, mask);
+ crypto_attr_alg_name(tb[1]), type, mask);
if (err)
goto err_free_inst;
@@ -82,17 +77,17 @@ struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
err = -EINVAL;
if (ivsize < sizeof(u64))
- goto err_drop_alg;
+ goto err_free_inst;
err = -ENAMETOOLONG;
if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME,
"%s(%s)", tmpl->name, alg->base.cra_name) >=
CRYPTO_MAX_ALG_NAME)
- goto err_drop_alg;
+ goto err_free_inst;
if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME,
"%s(%s)", tmpl->name, alg->base.cra_driver_name) >=
CRYPTO_MAX_ALG_NAME)
- goto err_drop_alg;
+ goto err_free_inst;
inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC;
inst->alg.base.cra_priority = alg->base.cra_priority;
@@ -111,10 +106,8 @@ struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
out:
return inst;
-err_drop_alg:
- crypto_drop_aead(spawn);
err_free_inst:
- kfree(inst);
+ aead_geniv_free(inst);
inst = ERR_PTR(err);
goto out;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 09/12] crypto: lrw - simplify error handling in create()
2020-02-26 4:59 [PATCH 00/12] crypto: more template instantiation cleanups Eric Biggers
` (7 preceding siblings ...)
2020-02-26 4:59 ` [PATCH 08/12] crypto: geniv - simply error handling in aead_geniv_alloc() Eric Biggers
@ 2020-02-26 4:59 ` Eric Biggers
2020-02-26 4:59 ` [PATCH 10/12] crypto: pcrypt - simplify error handling in pcrypt_create_aead() Eric Biggers
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Eric Biggers @ 2020-02-26 4:59 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
Simplify the error handling in the LRW template's ->create() function by
taking advantage of crypto_drop_skcipher() now accepting (as a no-op) a
spawn that hasn't been grabbed yet.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/lrw.c | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/crypto/lrw.c b/crypto/lrw.c
index 63c485c0d8a66..376d7ed3f1f87 100644
--- a/crypto/lrw.c
+++ b/crypto/lrw.c
@@ -343,15 +343,15 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb)
err = -EINVAL;
if (alg->base.cra_blocksize != LRW_BLOCK_SIZE)
- goto err_drop_spawn;
+ goto err_free_inst;
if (crypto_skcipher_alg_ivsize(alg))
- goto err_drop_spawn;
+ goto err_free_inst;
err = crypto_inst_setname(skcipher_crypto_instance(inst), "lrw",
&alg->base);
if (err)
- goto err_drop_spawn;
+ goto err_free_inst;
err = -EINVAL;
cipher_name = alg->base.cra_name;
@@ -364,20 +364,20 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb)
len = strlcpy(ecb_name, cipher_name + 4, sizeof(ecb_name));
if (len < 2 || len >= sizeof(ecb_name))
- goto err_drop_spawn;
+ goto err_free_inst;
if (ecb_name[len - 1] != ')')
- goto err_drop_spawn;
+ goto err_free_inst;
ecb_name[len - 1] = 0;
if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME,
"lrw(%s)", ecb_name) >= CRYPTO_MAX_ALG_NAME) {
err = -ENAMETOOLONG;
- goto err_drop_spawn;
+ goto err_free_inst;
}
} else
- goto err_drop_spawn;
+ goto err_free_inst;
inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC;
inst->alg.base.cra_priority = alg->base.cra_priority;
@@ -403,17 +403,11 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb)
inst->free = free;
err = skcipher_register_instance(tmpl, inst);
- if (err)
- goto err_drop_spawn;
-
-out:
- return err;
-
-err_drop_spawn:
- crypto_drop_skcipher(spawn);
+ if (err) {
err_free_inst:
- kfree(inst);
- goto out;
+ free(inst);
+ }
+ return err;
}
static struct crypto_template crypto_tmpl = {
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 10/12] crypto: pcrypt - simplify error handling in pcrypt_create_aead()
2020-02-26 4:59 [PATCH 00/12] crypto: more template instantiation cleanups Eric Biggers
` (8 preceding siblings ...)
2020-02-26 4:59 ` [PATCH 09/12] crypto: lrw - simplify error handling in create() Eric Biggers
@ 2020-02-26 4:59 ` Eric Biggers
2020-02-26 4:59 ` [PATCH 11/12] crypto: rsa-pkcs1pad - simplify error handling in pkcs1pad_create() Eric Biggers
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Eric Biggers @ 2020-02-26 4:59 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
Simplify the error handling in pcrypt_create_aead() by taking advantage
of crypto_grab_aead() now handling an ERR_PTR() name and by taking
advantage of crypto_drop_aead() now accepting (as a no-op) a spawn that
hasn't been grabbed yet.
This required also making padata_free_shell() accept a NULL argument.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/pcrypt.c | 33 +++++++++------------------------
kernel/padata.c | 7 ++++---
2 files changed, 13 insertions(+), 27 deletions(-)
diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
index 1b632139a8c1a..8bddc65cd5092 100644
--- a/crypto/pcrypt.c
+++ b/crypto/pcrypt.c
@@ -232,17 +232,12 @@ static int pcrypt_create_aead(struct crypto_template *tmpl, struct rtattr **tb,
struct crypto_attr_type *algt;
struct aead_instance *inst;
struct aead_alg *alg;
- const char *name;
int err;
algt = crypto_get_attr_type(tb);
if (IS_ERR(algt))
return PTR_ERR(algt);
- name = crypto_attr_alg_name(tb[1]);
- if (IS_ERR(name))
- return PTR_ERR(name);
-
inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
if (!inst)
return -ENOMEM;
@@ -252,21 +247,21 @@ static int pcrypt_create_aead(struct crypto_template *tmpl, struct rtattr **tb,
ctx = aead_instance_ctx(inst);
ctx->psenc = padata_alloc_shell(pencrypt);
if (!ctx->psenc)
- goto out_free_inst;
+ goto err_free_inst;
ctx->psdec = padata_alloc_shell(pdecrypt);
if (!ctx->psdec)
- goto out_free_psenc;
+ goto err_free_inst;
err = crypto_grab_aead(&ctx->spawn, aead_crypto_instance(inst),
- name, 0, 0);
+ crypto_attr_alg_name(tb[1]), 0, 0);
if (err)
- goto out_free_psdec;
+ goto err_free_inst;
alg = crypto_spawn_aead_alg(&ctx->spawn);
err = pcrypt_init_instance(aead_crypto_instance(inst), &alg->base);
if (err)
- goto out_drop_aead;
+ goto err_free_inst;
inst->alg.base.cra_flags = CRYPTO_ALG_ASYNC;
@@ -286,21 +281,11 @@ static int pcrypt_create_aead(struct crypto_template *tmpl, struct rtattr **tb,
inst->free = pcrypt_free;
err = aead_register_instance(tmpl, inst);
- if (err)
- goto out_drop_aead;
-
-out:
+ if (err) {
+err_free_inst:
+ pcrypt_free(inst);
+ }
return err;
-
-out_drop_aead:
- crypto_drop_aead(&ctx->spawn);
-out_free_psdec:
- padata_free_shell(ctx->psdec);
-out_free_psenc:
- padata_free_shell(ctx->psenc);
-out_free_inst:
- kfree(inst);
- goto out;
}
static int pcrypt_create(struct crypto_template *tmpl, struct rtattr **tb)
diff --git a/kernel/padata.c b/kernel/padata.c
index 62082597d4a2a..a6afa12fb75ee 100644
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -1038,12 +1038,13 @@ EXPORT_SYMBOL(padata_alloc_shell);
*/
void padata_free_shell(struct padata_shell *ps)
{
- struct padata_instance *pinst = ps->pinst;
+ if (!ps)
+ return;
- mutex_lock(&pinst->lock);
+ mutex_lock(&ps->pinst->lock);
list_del(&ps->list);
padata_free_pd(rcu_dereference_protected(ps->pd, 1));
- mutex_unlock(&pinst->lock);
+ mutex_unlock(&ps->pinst->lock);
kfree(ps);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 11/12] crypto: rsa-pkcs1pad - simplify error handling in pkcs1pad_create()
2020-02-26 4:59 [PATCH 00/12] crypto: more template instantiation cleanups Eric Biggers
` (9 preceding siblings ...)
2020-02-26 4:59 ` [PATCH 10/12] crypto: pcrypt - simplify error handling in pcrypt_create_aead() Eric Biggers
@ 2020-02-26 4:59 ` Eric Biggers
2020-02-26 4:59 ` [PATCH 12/12] crypto: xts - simplify error handling in ->create() Eric Biggers
2020-03-06 1:51 ` [PATCH 00/12] crypto: more template instantiation cleanups Herbert Xu
12 siblings, 0 replies; 14+ messages in thread
From: Eric Biggers @ 2020-02-26 4:59 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
Simplify the error handling in pkcs1pad_create() by taking advantage of
crypto_grab_akcipher() now handling an ERR_PTR() name and by taking
advantage of crypto_drop_akcipher() now accepting (as a no-op) a spawn
that hasn't been grabbed yet.
While we're at it, also simplify the way the hash_name optional argument
is handled. We only need to check whether it's present in one place,
and we can just assign directly to ctx->digest_info.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/rsa-pkcs1pad.c | 59 +++++++++++++++----------------------------
1 file changed, 20 insertions(+), 39 deletions(-)
diff --git a/crypto/rsa-pkcs1pad.c b/crypto/rsa-pkcs1pad.c
index 176b63afec8d9..d31031de51bcb 100644
--- a/crypto/rsa-pkcs1pad.c
+++ b/crypto/rsa-pkcs1pad.c
@@ -596,14 +596,11 @@ static void pkcs1pad_free(struct akcipher_instance *inst)
static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb)
{
- const struct rsa_asn1_template *digest_info;
struct crypto_attr_type *algt;
u32 mask;
struct akcipher_instance *inst;
struct pkcs1pad_inst_ctx *ctx;
- struct crypto_akcipher_spawn *spawn;
struct akcipher_alg *rsa_alg;
- const char *rsa_alg_name;
const char *hash_name;
int err;
@@ -616,60 +613,49 @@ static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb)
mask = crypto_requires_sync(algt->type, algt->mask);
- rsa_alg_name = crypto_attr_alg_name(tb[1]);
- if (IS_ERR(rsa_alg_name))
- return PTR_ERR(rsa_alg_name);
-
- hash_name = crypto_attr_alg_name(tb[2]);
- if (IS_ERR(hash_name))
- hash_name = NULL;
-
- if (hash_name) {
- digest_info = rsa_lookup_asn1(hash_name);
- if (!digest_info)
- return -EINVAL;
- } else
- digest_info = NULL;
-
inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
if (!inst)
return -ENOMEM;
ctx = akcipher_instance_ctx(inst);
- spawn = &ctx->spawn;
- ctx->digest_info = digest_info;
- err = crypto_grab_akcipher(spawn, akcipher_crypto_instance(inst),
- rsa_alg_name, 0, mask);
+ err = crypto_grab_akcipher(&ctx->spawn, akcipher_crypto_instance(inst),
+ crypto_attr_alg_name(tb[1]), 0, mask);
if (err)
- goto out_free_inst;
+ goto err_free_inst;
- rsa_alg = crypto_spawn_akcipher_alg(spawn);
+ rsa_alg = crypto_spawn_akcipher_alg(&ctx->spawn);
err = -ENAMETOOLONG;
-
- if (!hash_name) {
+ hash_name = crypto_attr_alg_name(tb[2]);
+ if (IS_ERR(hash_name)) {
if (snprintf(inst->alg.base.cra_name,
CRYPTO_MAX_ALG_NAME, "pkcs1pad(%s)",
rsa_alg->base.cra_name) >= CRYPTO_MAX_ALG_NAME)
- goto out_drop_alg;
+ goto err_free_inst;
if (snprintf(inst->alg.base.cra_driver_name,
CRYPTO_MAX_ALG_NAME, "pkcs1pad(%s)",
rsa_alg->base.cra_driver_name) >=
CRYPTO_MAX_ALG_NAME)
- goto out_drop_alg;
+ goto err_free_inst;
} else {
+ ctx->digest_info = rsa_lookup_asn1(hash_name);
+ if (!ctx->digest_info) {
+ err = -EINVAL;
+ goto err_free_inst;
+ }
+
if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME,
"pkcs1pad(%s,%s)", rsa_alg->base.cra_name,
hash_name) >= CRYPTO_MAX_ALG_NAME)
- goto out_drop_alg;
+ goto err_free_inst;
if (snprintf(inst->alg.base.cra_driver_name,
CRYPTO_MAX_ALG_NAME, "pkcs1pad(%s,%s)",
rsa_alg->base.cra_driver_name,
hash_name) >= CRYPTO_MAX_ALG_NAME)
- goto out_drop_alg;
+ goto err_free_inst;
}
inst->alg.base.cra_flags = rsa_alg->base.cra_flags & CRYPTO_ALG_ASYNC;
@@ -691,15 +677,10 @@ static int pkcs1pad_create(struct crypto_template *tmpl, struct rtattr **tb)
inst->free = pkcs1pad_free;
err = akcipher_register_instance(tmpl, inst);
- if (err)
- goto out_drop_alg;
-
- return 0;
-
-out_drop_alg:
- crypto_drop_akcipher(spawn);
-out_free_inst:
- kfree(inst);
+ if (err) {
+err_free_inst:
+ pkcs1pad_free(inst);
+ }
return err;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 12/12] crypto: xts - simplify error handling in ->create()
2020-02-26 4:59 [PATCH 00/12] crypto: more template instantiation cleanups Eric Biggers
` (10 preceding siblings ...)
2020-02-26 4:59 ` [PATCH 11/12] crypto: rsa-pkcs1pad - simplify error handling in pkcs1pad_create() Eric Biggers
@ 2020-02-26 4:59 ` Eric Biggers
2020-03-06 1:51 ` [PATCH 00/12] crypto: more template instantiation cleanups Herbert Xu
12 siblings, 0 replies; 14+ messages in thread
From: Eric Biggers @ 2020-02-26 4:59 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
Simplify the error handling in the XTS template's ->create() function by
taking advantage of crypto_drop_skcipher() now accepting (as a no-op) a
spawn that hasn't been grabbed yet.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
crypto/xts.c | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/crypto/xts.c b/crypto/xts.c
index 29efa15f14954..dbdd8af629e69 100644
--- a/crypto/xts.c
+++ b/crypto/xts.c
@@ -379,15 +379,15 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb)
err = -EINVAL;
if (alg->base.cra_blocksize != XTS_BLOCK_SIZE)
- goto err_drop_spawn;
+ goto err_free_inst;
if (crypto_skcipher_alg_ivsize(alg))
- goto err_drop_spawn;
+ goto err_free_inst;
err = crypto_inst_setname(skcipher_crypto_instance(inst), "xts",
&alg->base);
if (err)
- goto err_drop_spawn;
+ goto err_free_inst;
err = -EINVAL;
cipher_name = alg->base.cra_name;
@@ -400,20 +400,20 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb)
len = strlcpy(ctx->name, cipher_name + 4, sizeof(ctx->name));
if (len < 2 || len >= sizeof(ctx->name))
- goto err_drop_spawn;
+ goto err_free_inst;
if (ctx->name[len - 1] != ')')
- goto err_drop_spawn;
+ goto err_free_inst;
ctx->name[len - 1] = 0;
if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME,
"xts(%s)", ctx->name) >= CRYPTO_MAX_ALG_NAME) {
err = -ENAMETOOLONG;
- goto err_drop_spawn;
+ goto err_free_inst;
}
} else
- goto err_drop_spawn;
+ goto err_free_inst;
inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC;
inst->alg.base.cra_priority = alg->base.cra_priority;
@@ -437,17 +437,11 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb)
inst->free = free;
err = skcipher_register_instance(tmpl, inst);
- if (err)
- goto err_drop_spawn;
-
-out:
- return err;
-
-err_drop_spawn:
- crypto_drop_skcipher(&ctx->spawn);
+ if (err) {
err_free_inst:
- kfree(inst);
- goto out;
+ free(inst);
+ }
+ return err;
}
static struct crypto_template crypto_tmpl = {
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 00/12] crypto: more template instantiation cleanups
2020-02-26 4:59 [PATCH 00/12] crypto: more template instantiation cleanups Eric Biggers
` (11 preceding siblings ...)
2020-02-26 4:59 ` [PATCH 12/12] crypto: xts - simplify error handling in ->create() Eric Biggers
@ 2020-03-06 1:51 ` Herbert Xu
12 siblings, 0 replies; 14+ messages in thread
From: Herbert Xu @ 2020-03-06 1:51 UTC (permalink / raw)
To: Eric Biggers; +Cc: linux-crypto
Eric Biggers <ebiggers@kernel.org> wrote:
> This series simplifies error handling in the remaining crypto templates,
> taking advantage of the changes I made last release that made
> crypto_grab_*() accept ERR_PTR() names and crypto_drop_*() accept
> spawns that haven't been grabbed yet:
> https://lore.kernel.org/r/20200103035908.12048-1-ebiggers@kernel.org
>
> Many templates were already converted to the new style by that series.
> This series just handles the remainder.
>
> This series is an internal cleanup only; there are no changes for users
> of the crypto API. Net change is 124 lines of code removed.
>
> Eric Biggers (12):
> crypto: authencesn - fix weird comma-terminated line
> crypto: ccm - simplify error handling in crypto_rfc4309_create()
> crypto: cryptd - simplify error handling in cryptd_create_*()
> crypto: ctr - simplify error handling in crypto_rfc3686_create()
> crypto: cts - simplify error handling in crypto_cts_create()
> crypto: gcm - simplify error handling in crypto_rfc4106_create()
> crypto: gcm - simplify error handling in crypto_rfc4543_create()
> crypto: geniv - simply error handling in aead_geniv_alloc()
> crypto: lrw - simplify error handling in create()
> crypto: pcrypt - simplify error handling in pcrypt_create_aead()
> crypto: rsa-pkcs1pad - simplify error handling in pkcs1pad_create()
> crypto: xts - simplify error handling in ->create()
>
> crypto/authencesn.c | 2 +-
> crypto/ccm.c | 29 ++++++-------------
> crypto/cryptd.c | 37 ++++++++----------------
> crypto/ctr.c | 29 ++++++-------------
> crypto/cts.c | 27 ++++++------------
> crypto/gcm.c | 66 ++++++++++++++-----------------------------
> crypto/geniv.c | 17 ++++-------
> crypto/lrw.c | 28 ++++++++----------
> crypto/pcrypt.c | 33 ++++++----------------
> crypto/rsa-pkcs1pad.c | 59 +++++++++++++-------------------------
> crypto/xts.c | 28 ++++++++----------
> kernel/padata.c | 7 +++--
> 12 files changed, 119 insertions(+), 243 deletions(-)
All applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2020-03-06 1:51 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 4:59 [PATCH 00/12] crypto: more template instantiation cleanups Eric Biggers
2020-02-26 4:59 ` [PATCH 01/12] crypto: authencesn - fix weird comma-terminated line Eric Biggers
2020-02-26 4:59 ` [PATCH 02/12] crypto: ccm - simplify error handling in crypto_rfc4309_create() Eric Biggers
2020-02-26 4:59 ` [PATCH 03/12] crypto: cryptd - simplify error handling in cryptd_create_*() Eric Biggers
2020-02-26 4:59 ` [PATCH 04/12] crypto: ctr - simplify error handling in crypto_rfc3686_create() Eric Biggers
2020-02-26 4:59 ` [PATCH 05/12] crypto: cts - simplify error handling in crypto_cts_create() Eric Biggers
2020-02-26 4:59 ` [PATCH 06/12] crypto: gcm - simplify error handling in crypto_rfc4106_create() Eric Biggers
2020-02-26 4:59 ` [PATCH 07/12] crypto: gcm - simplify error handling in crypto_rfc4543_create() Eric Biggers
2020-02-26 4:59 ` [PATCH 08/12] crypto: geniv - simply error handling in aead_geniv_alloc() Eric Biggers
2020-02-26 4:59 ` [PATCH 09/12] crypto: lrw - simplify error handling in create() Eric Biggers
2020-02-26 4:59 ` [PATCH 10/12] crypto: pcrypt - simplify error handling in pcrypt_create_aead() Eric Biggers
2020-02-26 4:59 ` [PATCH 11/12] crypto: rsa-pkcs1pad - simplify error handling in pkcs1pad_create() Eric Biggers
2020-02-26 4:59 ` [PATCH 12/12] crypto: xts - simplify error handling in ->create() Eric Biggers
2020-03-06 1:51 ` [PATCH 00/12] crypto: more template instantiation cleanups Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).