Skip to content

Commit 4a77948

Browse files
committed
crypto: api - Move type exit function into crypto_tfm
The type exit function needs to undo any allocations done by the type init function. However, the type init function may differ depending on the upper-level type of the transform (e.g., a crypto_blkcipher instantiated as a crypto_ablkcipher). So we need to move the exit function out of the lower-level structure and into crypto_tfm itself. As it stands this is a no-op since nobody uses exit functions at all. However, all cases where a lower-level type is instantiated as a different upper-level type (such as blkcipher as ablkcipher) will be converted such that they allocate the underlying transform and use that instead of casting (e.g., crypto_ablkcipher casted into crypto_blkcipher). That will need to use a different exit function depending on the upper-level type. This patch also allows the type init/exit functions to call (or not) cra_init/cra_exit instead of always calling them from the top level. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 2566578 commit 4a77948

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎crypto/api.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ static void crypto_exit_ops(struct crypto_tfm *tfm)
300300
const struct crypto_type *type = tfm->__crt_alg->cra_type;
301301

302302
if (type) {
303-
if (type->exit)
304-
type->exit(tfm);
303+
if (tfm->exit)
304+
tfm->exit(tfm);
305305
return;
306306
}
307307

@@ -379,17 +379,16 @@ struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
379379
if (err)
380380
goto out_free_tfm;
381381

382-
if (alg->cra_init && (err = alg->cra_init(tfm))) {
383-
if (err == -EAGAIN)
384-
crypto_shoot_alg(alg);
382+
if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm)))
385383
goto cra_init_failed;
386-
}
387384

388385
goto out;
389386

390387
cra_init_failed:
391388
crypto_exit_ops(tfm);
392389
out_free_tfm:
390+
if (err == -EAGAIN)
391+
crypto_shoot_alg(alg);
393392
kfree(tfm);
394393
out_err:
395394
tfm = ERR_PTR(err);
@@ -469,7 +468,7 @@ void crypto_free_tfm(struct crypto_tfm *tfm)
469468
alg = tfm->__crt_alg;
470469
size = sizeof(*tfm) + alg->cra_ctxsize;
471470

472-
if (alg->cra_exit)
471+
if (!tfm->exit && alg->cra_exit)
473472
alg->cra_exit(tfm);
474473
crypto_exit_ops(tfm);
475474
crypto_mod_put(alg);

‎include/crypto/algapi.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ struct seq_file;
2323
struct crypto_type {
2424
unsigned int (*ctxsize)(struct crypto_alg *alg, u32 type, u32 mask);
2525
int (*init)(struct crypto_tfm *tfm, u32 type, u32 mask);
26-
void (*exit)(struct crypto_tfm *tfm);
2726
void (*show)(struct seq_file *m, struct crypto_alg *alg);
2827
};
2928

‎include/linux/crypto.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ struct crypto_tfm {
480480
struct compress_tfm compress;
481481
struct rng_tfm rng;
482482
} crt_u;
483+
484+
void (*exit)(struct crypto_tfm *tfm);
483485

484486
struct crypto_alg *__crt_alg;
485487

0 commit comments

Comments
 (0)