Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[linux-2.6-microblaze.git] / fs / crypto / fname.c
index 8606da1..0b94cd2 100644 (file)
 #include <linux/ratelimit.h>
 #include "fscrypt_private.h"
 
-/**
- * fname_crypt_complete() - completion callback for filename crypto
- * @req: The asynchronous cipher request context
- * @res: The result of the cipher operation
- */
-static void fname_crypt_complete(struct crypto_async_request *req, int res)
-{
-       struct fscrypt_completion_result *ecr = req->data;
-
-       if (res == -EINPROGRESS)
-               return;
-       ecr->res = res;
-       complete(&ecr->completion);
-}
-
 /**
  * fname_encrypt() - encrypt a filename
  *
@@ -41,7 +26,7 @@ static int fname_encrypt(struct inode *inode,
                        const struct qstr *iname, struct fscrypt_str *oname)
 {
        struct skcipher_request *req = NULL;
-       DECLARE_FS_COMPLETION_RESULT(ecr);
+       DECLARE_CRYPTO_WAIT(wait);
        struct fscrypt_info *ci = inode->i_crypt_info;
        struct crypto_skcipher *tfm = ci->ci_ctfm;
        int res = 0;
@@ -77,17 +62,12 @@ static int fname_encrypt(struct inode *inode,
        }
        skcipher_request_set_callback(req,
                        CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
-                       fname_crypt_complete, &ecr);
+                       crypto_req_done, &wait);
        sg_init_one(&sg, oname->name, cryptlen);
        skcipher_request_set_crypt(req, &sg, &sg, cryptlen, iv);
 
        /* Do the encryption */
-       res = crypto_skcipher_encrypt(req);
-       if (res == -EINPROGRESS || res == -EBUSY) {
-               /* Request is being completed asynchronously; wait for it */
-               wait_for_completion(&ecr.completion);
-               res = ecr.res;
-       }
+       res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
        skcipher_request_free(req);
        if (res < 0) {
                printk_ratelimited(KERN_ERR
@@ -111,7 +91,7 @@ static int fname_decrypt(struct inode *inode,
                                struct fscrypt_str *oname)
 {
        struct skcipher_request *req = NULL;
-       DECLARE_FS_COMPLETION_RESULT(ecr);
+       DECLARE_CRYPTO_WAIT(wait);
        struct scatterlist src_sg, dst_sg;
        struct fscrypt_info *ci = inode->i_crypt_info;
        struct crypto_skcipher *tfm = ci->ci_ctfm;
@@ -132,7 +112,7 @@ static int fname_decrypt(struct inode *inode,
        }
        skcipher_request_set_callback(req,
                CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
-               fname_crypt_complete, &ecr);
+               crypto_req_done, &wait);
 
        /* Initialize IV */
        memset(iv, 0, FS_CRYPTO_BLOCK_SIZE);
@@ -141,11 +121,7 @@ static int fname_decrypt(struct inode *inode,
        sg_init_one(&src_sg, iname->name, iname->len);
        sg_init_one(&dst_sg, oname->name, oname->len);
        skcipher_request_set_crypt(req, &src_sg, &dst_sg, iname->len, iv);
-       res = crypto_skcipher_decrypt(req);
-       if (res == -EINPROGRESS || res == -EBUSY) {
-               wait_for_completion(&ecr.completion);
-               res = ecr.res;
-       }
+       res = crypto_wait_req(crypto_skcipher_decrypt(req), &wait);
        skcipher_request_free(req);
        if (res < 0) {
                printk_ratelimited(KERN_ERR