Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[cascardo/linux.git] / crypto / algif_skcipher.c
index 4f45dab..c12207c 100644 (file)
@@ -251,6 +251,7 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
        struct af_alg_control con = {};
        long copied = 0;
        bool enc = 0;
+       bool init = 0;
        int err;
        int i;
 
@@ -259,6 +260,7 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
                if (err)
                        return err;
 
+               init = 1;
                switch (con.op) {
                case ALG_OP_ENCRYPT:
                        enc = 1;
@@ -280,7 +282,7 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
        if (!ctx->more && ctx->used)
                goto unlock;
 
-       if (!ctx->used) {
+       if (init) {
                ctx->enc = enc;
                if (con.iv)
                        memcpy(ctx->iv, con.iv->iv, ivsize);
@@ -359,8 +361,6 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
        err = 0;
 
        ctx->more = msg->msg_flags & MSG_MORE;
-       if (!ctx->more && !list_empty(&ctx->tsgl))
-               sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list);
 
 unlock:
        skcipher_data_wakeup(sk);
@@ -408,8 +408,6 @@ static ssize_t skcipher_sendpage(struct socket *sock, struct page *page,
 
 done:
        ctx->more = flags & MSG_MORE;
-       if (!ctx->more && !list_empty(&ctx->tsgl))
-               sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list);
 
 unlock:
        skcipher_data_wakeup(sk);
@@ -448,14 +446,13 @@ static int skcipher_recvmsg(struct kiocb *unused, struct socket *sock,
                        while (!sg->length)
                                sg++;
 
-                       used = ctx->used;
-                       if (!used) {
+                       if (!ctx->used) {
                                err = skcipher_wait_for_data(sk, flags);
                                if (err)
                                        goto unlock;
                        }
 
-                       used = min_t(unsigned long, used, seglen);
+                       used = min_t(unsigned long, ctx->used, seglen);
 
                        used = af_alg_make_sg(&ctx->rsgl, from, used, 1);
                        err = used;
@@ -566,7 +563,7 @@ static void skcipher_sock_destruct(struct sock *sk)
        struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(&ctx->req);
 
        skcipher_free_sgl(sk);
-       sock_kfree_s(sk, ctx->iv, crypto_ablkcipher_ivsize(tfm));
+       sock_kzfree_s(sk, ctx->iv, crypto_ablkcipher_ivsize(tfm));
        sock_kfree_s(sk, ctx, ctx->len);
        af_alg_release_parent(sk);
 }