Commit 413c55e0 authored by Adam J. Richter's avatar Adam J. Richter Committed by David S. Miller

[CRYPTO]: Simplify crypto memory allocation.

parent 561e33a2
...@@ -123,44 +123,26 @@ struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags) ...@@ -123,44 +123,26 @@ struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
if (alg == NULL) if (alg == NULL)
goto out; goto out;
tfm = kmalloc(sizeof(*tfm), GFP_KERNEL); tfm = kmalloc(sizeof(*tfm) + alg->cra_ctxsize, GFP_KERNEL);
if (tfm == NULL) if (tfm == NULL)
goto out_put; goto out_put;
memset(tfm, 0, sizeof(*tfm)); memset(tfm, 0, sizeof(*tfm));
if (alg->cra_ctxsize) { tfm->crt_ctx = (void*) &tfm[1];
tfm->crt_ctx = kmalloc(alg->cra_ctxsize, GFP_KERNEL);
if (tfm->crt_ctx == NULL)
goto out_free_tfm;
}
tfm->__crt_alg = alg; tfm->__crt_alg = alg;
if (alg->cra_blocksize) {
tfm->crt_work_block = kmalloc(alg->cra_blocksize + 1,
GFP_KERNEL);
if (tfm->crt_work_block == NULL)
goto out_free_ctx;
}
if (crypto_init_flags(tfm, flags)) if (crypto_init_flags(tfm, flags))
goto out_free_work_block; goto out_free_tfm;
if (crypto_init_ops(tfm)) { if (crypto_init_ops(tfm)) {
crypto_exit_ops(tfm); crypto_exit_ops(tfm);
goto out_free_ctx; goto out_free_tfm;
} }
goto out; goto out;
out_free_work_block:
if (tfm->__crt_alg->cra_blocksize)
kfree(tfm->crt_work_block);
out_free_ctx:
if (tfm->__crt_alg->cra_ctxsize)
kfree(tfm->crt_ctx);
out_free_tfm: out_free_tfm:
kfree(tfm); kfree(tfm);
tfm = NULL; tfm = NULL;
...@@ -172,12 +154,6 @@ struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags) ...@@ -172,12 +154,6 @@ struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
void crypto_free_tfm(struct crypto_tfm *tfm) void crypto_free_tfm(struct crypto_tfm *tfm)
{ {
if (tfm->__crt_alg->cra_ctxsize)
kfree(tfm->crt_ctx);
if (tfm->__crt_alg->cra_blocksize)
kfree(tfm->crt_work_block);
if (crypto_tfm_alg_type(tfm) == CRYPTO_ALG_TYPE_CIPHER) if (crypto_tfm_alg_type(tfm) == CRYPTO_ALG_TYPE_CIPHER)
if (tfm->crt_cipher.cit_iv) if (tfm->crt_cipher.cit_iv)
kfree(tfm->crt_cipher.cit_iv); kfree(tfm->crt_cipher.cit_iv);
......
...@@ -161,7 +161,6 @@ struct compress_tfm { ...@@ -161,7 +161,6 @@ struct compress_tfm {
struct crypto_tfm { struct crypto_tfm {
void *crt_ctx; void *crt_ctx;
void *crt_work_block;
u32 crt_flags; u32 crt_flags;
union { union {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment