Merge tag 'for-5.6/io_uring-vfs-2020-01-29' of git://git.kernel.dk/linux-block
[linux-2.6-microblaze.git] / crypto / pcrypt.c
index 543792e..1b63213 100644 (file)
@@ -13,7 +13,6 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/slab.h>
-#include <linux/notifier.h>
 #include <linux/kobject.h>
 #include <linux/cpu.h>
 #include <crypto/pcrypt.h>
@@ -24,6 +23,8 @@ static struct kset           *pcrypt_kset;
 
 struct pcrypt_instance_ctx {
        struct crypto_aead_spawn spawn;
+       struct padata_shell *psenc;
+       struct padata_shell *psdec;
        atomic_t tfm_count;
 };
 
@@ -32,6 +33,12 @@ struct pcrypt_aead_ctx {
        unsigned int cb_cpu;
 };
 
+static inline struct pcrypt_instance_ctx *pcrypt_tfm_ictx(
+       struct crypto_aead *tfm)
+{
+       return aead_instance_ctx(aead_alg_instance(tfm));
+}
+
 static int pcrypt_aead_setkey(struct crypto_aead *parent,
                              const u8 *key, unsigned int keylen)
 {
@@ -63,7 +70,6 @@ static void pcrypt_aead_done(struct crypto_async_request *areq, int err)
        struct padata_priv *padata = pcrypt_request_padata(preq);
 
        padata->info = err;
-       req->base.flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
 
        padata_do_serial(padata);
 }
@@ -90,6 +96,9 @@ static int pcrypt_aead_encrypt(struct aead_request *req)
        struct crypto_aead *aead = crypto_aead_reqtfm(req);
        struct pcrypt_aead_ctx *ctx = crypto_aead_ctx(aead);
        u32 flags = aead_request_flags(req);
+       struct pcrypt_instance_ctx *ictx;
+
+       ictx = pcrypt_tfm_ictx(aead);
 
        memset(padata, 0, sizeof(struct padata_priv));
 
@@ -103,7 +112,7 @@ static int pcrypt_aead_encrypt(struct aead_request *req)
                               req->cryptlen, req->iv);
        aead_request_set_ad(creq, req->assoclen);
 
-       err = padata_do_parallel(pencrypt, padata, &ctx->cb_cpu);
+       err = padata_do_parallel(ictx->psenc, padata, &ctx->cb_cpu);
        if (!err)
                return -EINPROGRESS;
 
@@ -132,6 +141,9 @@ static int pcrypt_aead_decrypt(struct aead_request *req)
        struct crypto_aead *aead = crypto_aead_reqtfm(req);
        struct pcrypt_aead_ctx *ctx = crypto_aead_ctx(aead);
        u32 flags = aead_request_flags(req);
+       struct pcrypt_instance_ctx *ictx;
+
+       ictx = pcrypt_tfm_ictx(aead);
 
        memset(padata, 0, sizeof(struct padata_priv));
 
@@ -145,7 +157,7 @@ static int pcrypt_aead_decrypt(struct aead_request *req)
                               req->cryptlen, req->iv);
        aead_request_set_ad(creq, req->assoclen);
 
-       err = padata_do_parallel(pdecrypt, padata, &ctx->cb_cpu);
+       err = padata_do_parallel(ictx->psdec, padata, &ctx->cb_cpu);
        if (!err)
                return -EINPROGRESS;
 
@@ -192,6 +204,8 @@ static void pcrypt_free(struct aead_instance *inst)
        struct pcrypt_instance_ctx *ctx = aead_instance_ctx(inst);
 
        crypto_drop_aead(&ctx->spawn);
+       padata_free_shell(ctx->psdec);
+       padata_free_shell(ctx->psenc);
        kfree(inst);
 }
 
@@ -233,12 +247,21 @@ static int pcrypt_create_aead(struct crypto_template *tmpl, struct rtattr **tb,
        if (!inst)
                return -ENOMEM;
 
+       err = -ENOMEM;
+
        ctx = aead_instance_ctx(inst);
-       crypto_set_aead_spawn(&ctx->spawn, aead_crypto_instance(inst));
+       ctx->psenc = padata_alloc_shell(pencrypt);
+       if (!ctx->psenc)
+               goto out_free_inst;
+
+       ctx->psdec = padata_alloc_shell(pdecrypt);
+       if (!ctx->psdec)
+               goto out_free_psenc;
 
-       err = crypto_grab_aead(&ctx->spawn, name, 0, 0);
+       err = crypto_grab_aead(&ctx->spawn, aead_crypto_instance(inst),
+                              name, 0, 0);
        if (err)
-               goto out_free_inst;
+               goto out_free_psdec;
 
        alg = crypto_spawn_aead_alg(&ctx->spawn);
        err = pcrypt_init_instance(aead_crypto_instance(inst), &alg->base);
@@ -271,6 +294,10 @@ out:
 
 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;
@@ -362,11 +389,12 @@ err:
 
 static void __exit pcrypt_exit(void)
 {
+       crypto_unregister_template(&pcrypt_tmpl);
+
        pcrypt_fini_padata(pencrypt);
        pcrypt_fini_padata(pdecrypt);
 
        kset_unregister(pcrypt_kset);
-       crypto_unregister_template(&pcrypt_tmpl);
 }
 
 subsys_initcall(pcrypt_init);