mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 20:51:03 +02:00
crypto: cryptd - simplify error handling in cryptd_create_*()
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> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
@@ -369,7 +369,6 @@ static int cryptd_create_skcipher(struct crypto_template *tmpl,
|
|||||||
struct skcipherd_instance_ctx *ctx;
|
struct skcipherd_instance_ctx *ctx;
|
||||||
struct skcipher_instance *inst;
|
struct skcipher_instance *inst;
|
||||||
struct skcipher_alg *alg;
|
struct skcipher_alg *alg;
|
||||||
const char *name;
|
|
||||||
u32 type;
|
u32 type;
|
||||||
u32 mask;
|
u32 mask;
|
||||||
int err;
|
int err;
|
||||||
@@ -379,10 +378,6 @@ static int cryptd_create_skcipher(struct crypto_template *tmpl,
|
|||||||
|
|
||||||
cryptd_check_internal(tb, &type, &mask);
|
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);
|
inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
|
||||||
if (!inst)
|
if (!inst)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@@ -391,14 +386,14 @@ static int cryptd_create_skcipher(struct crypto_template *tmpl,
|
|||||||
ctx->queue = queue;
|
ctx->queue = queue;
|
||||||
|
|
||||||
err = crypto_grab_skcipher(&ctx->spawn, skcipher_crypto_instance(inst),
|
err = crypto_grab_skcipher(&ctx->spawn, skcipher_crypto_instance(inst),
|
||||||
name, type, mask);
|
crypto_attr_alg_name(tb[1]), type, mask);
|
||||||
if (err)
|
if (err)
|
||||||
goto out_free_inst;
|
goto err_free_inst;
|
||||||
|
|
||||||
alg = crypto_spawn_skcipher_alg(&ctx->spawn);
|
alg = crypto_spawn_skcipher_alg(&ctx->spawn);
|
||||||
err = cryptd_init_instance(skcipher_crypto_instance(inst), &alg->base);
|
err = cryptd_init_instance(skcipher_crypto_instance(inst), &alg->base);
|
||||||
if (err)
|
if (err)
|
||||||
goto out_drop_skcipher;
|
goto err_free_inst;
|
||||||
|
|
||||||
inst->alg.base.cra_flags = CRYPTO_ALG_ASYNC |
|
inst->alg.base.cra_flags = CRYPTO_ALG_ASYNC |
|
||||||
(alg->base.cra_flags & CRYPTO_ALG_INTERNAL);
|
(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);
|
err = skcipher_register_instance(tmpl, inst);
|
||||||
if (err) {
|
if (err) {
|
||||||
out_drop_skcipher:
|
err_free_inst:
|
||||||
crypto_drop_skcipher(&ctx->spawn);
|
cryptd_skcipher_free(inst);
|
||||||
out_free_inst:
|
|
||||||
kfree(inst);
|
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -694,8 +687,7 @@ static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb,
|
|||||||
err = ahash_register_instance(tmpl, inst);
|
err = ahash_register_instance(tmpl, inst);
|
||||||
if (err) {
|
if (err) {
|
||||||
err_free_inst:
|
err_free_inst:
|
||||||
crypto_drop_shash(&ctx->spawn);
|
cryptd_hash_free(inst);
|
||||||
kfree(inst);
|
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -833,17 +825,12 @@ static int cryptd_create_aead(struct crypto_template *tmpl,
|
|||||||
struct aead_instance_ctx *ctx;
|
struct aead_instance_ctx *ctx;
|
||||||
struct aead_instance *inst;
|
struct aead_instance *inst;
|
||||||
struct aead_alg *alg;
|
struct aead_alg *alg;
|
||||||
const char *name;
|
|
||||||
u32 type = 0;
|
u32 type = 0;
|
||||||
u32 mask = CRYPTO_ALG_ASYNC;
|
u32 mask = CRYPTO_ALG_ASYNC;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
cryptd_check_internal(tb, &type, &mask);
|
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);
|
inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
|
||||||
if (!inst)
|
if (!inst)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@@ -852,14 +839,14 @@ static int cryptd_create_aead(struct crypto_template *tmpl,
|
|||||||
ctx->queue = queue;
|
ctx->queue = queue;
|
||||||
|
|
||||||
err = crypto_grab_aead(&ctx->aead_spawn, aead_crypto_instance(inst),
|
err = crypto_grab_aead(&ctx->aead_spawn, aead_crypto_instance(inst),
|
||||||
name, type, mask);
|
crypto_attr_alg_name(tb[1]), type, mask);
|
||||||
if (err)
|
if (err)
|
||||||
goto out_free_inst;
|
goto err_free_inst;
|
||||||
|
|
||||||
alg = crypto_spawn_aead_alg(&ctx->aead_spawn);
|
alg = crypto_spawn_aead_alg(&ctx->aead_spawn);
|
||||||
err = cryptd_init_instance(aead_crypto_instance(inst), &alg->base);
|
err = cryptd_init_instance(aead_crypto_instance(inst), &alg->base);
|
||||||
if (err)
|
if (err)
|
||||||
goto out_drop_aead;
|
goto err_free_inst;
|
||||||
|
|
||||||
inst->alg.base.cra_flags = CRYPTO_ALG_ASYNC |
|
inst->alg.base.cra_flags = CRYPTO_ALG_ASYNC |
|
||||||
(alg->base.cra_flags & CRYPTO_ALG_INTERNAL);
|
(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);
|
err = aead_register_instance(tmpl, inst);
|
||||||
if (err) {
|
if (err) {
|
||||||
out_drop_aead:
|
err_free_inst:
|
||||||
crypto_drop_aead(&ctx->aead_spawn);
|
cryptd_aead_free(inst);
|
||||||
out_free_inst:
|
|
||||||
kfree(inst);
|
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user