ethtool: add speed/duplex validation functions
[cascardo/linux.git] / crypto / algif_skcipher.c
index 4a5bdb6..38c1aa8 100644 (file)
@@ -243,7 +243,7 @@ static void skcipher_wmem_wakeup(struct sock *sk)
 
        rcu_read_lock();
        wq = rcu_dereference(sk->sk_wq);
-       if (wq_has_sleeper(wq))
+       if (skwq_has_sleeper(wq))
                wake_up_interruptible_sync_poll(&wq->wait, POLLIN |
                                                           POLLRDNORM |
                                                           POLLRDBAND);
@@ -293,7 +293,7 @@ static void skcipher_data_wakeup(struct sock *sk)
 
        rcu_read_lock();
        wq = rcu_dereference(sk->sk_wq);
-       if (wq_has_sleeper(wq))
+       if (skwq_has_sleeper(wq))
                wake_up_interruptible_sync_poll(&wq->wait, POLLOUT |
                                                           POLLRDNORM |
                                                           POLLRDBAND);
@@ -392,7 +392,8 @@ static int skcipher_sendmsg(struct socket *sock, struct msghdr *msg,
 
                sgl = list_entry(ctx->tsgl.prev, struct skcipher_sg_list, list);
                sg = sgl->sg;
-               sg_unmark_end(sg + sgl->cur);
+               if (sgl->cur)
+                       sg_unmark_end(sg + sgl->cur - 1);
                do {
                        i = sgl->cur;
                        plen = min_t(size_t, len, PAGE_SIZE);
@@ -647,13 +648,6 @@ static int skcipher_recvmsg_sync(struct socket *sock, struct msghdr *msg,
 
        lock_sock(sk);
        while (msg_data_left(msg)) {
-               sgl = list_first_entry(&ctx->tsgl,
-                                      struct skcipher_sg_list, list);
-               sg = sgl->sg;
-
-               while (!sg->length)
-                       sg++;
-
                if (!ctx->used) {
                        err = skcipher_wait_for_data(sk, flags);
                        if (err)
@@ -674,6 +668,13 @@ static int skcipher_recvmsg_sync(struct socket *sock, struct msghdr *msg,
                if (!used)
                        goto free;
 
+               sgl = list_first_entry(&ctx->tsgl,
+                                      struct skcipher_sg_list, list);
+               sg = sgl->sg;
+
+               while (!sg->length)
+                       sg++;
+
                skcipher_request_set_crypt(&ctx->req, sg, ctx->rsgl.sg, used,
                                           ctx->iv);
 
@@ -755,22 +756,23 @@ static struct proto_ops algif_skcipher_ops = {
 
 static int skcipher_check_key(struct socket *sock)
 {
-       int err;
+       int err = 0;
        struct sock *psk;
        struct alg_sock *pask;
        struct skcipher_tfm *tfm;
        struct sock *sk = sock->sk;
        struct alg_sock *ask = alg_sk(sk);
 
+       lock_sock(sk);
        if (ask->refcnt)
-               return 0;
+               goto unlock_child;
 
        psk = ask->parent;
        pask = alg_sk(ask->parent);
        tfm = pask->private;
 
        err = -ENOKEY;
-       lock_sock(psk);
+       lock_sock_nested(psk, SINGLE_DEPTH_NESTING);
        if (!tfm->has_key)
                goto unlock;
 
@@ -784,6 +786,8 @@ static int skcipher_check_key(struct socket *sock)
 
 unlock:
        release_sock(psk);
+unlock_child:
+       release_sock(sk);
 
        return err;
 }
@@ -895,7 +899,7 @@ static void skcipher_wait(struct sock *sk)
                msleep(100);
 }
 
-static void skcipher_sock_destruct_common(struct sock *sk)
+static void skcipher_sock_destruct(struct sock *sk)
 {
        struct alg_sock *ask = alg_sk(sk);
        struct skcipher_ctx *ctx = ask->private;
@@ -907,33 +911,10 @@ static void skcipher_sock_destruct_common(struct sock *sk)
        skcipher_free_sgl(sk);
        sock_kzfree_s(sk, ctx->iv, crypto_skcipher_ivsize(tfm));
        sock_kfree_s(sk, ctx, ctx->len);
-}
-
-static void skcipher_sock_destruct(struct sock *sk)
-{
-       skcipher_sock_destruct_common(sk);
        af_alg_release_parent(sk);
 }
 
-static void skcipher_release_parent_nokey(struct sock *sk)
-{
-       struct alg_sock *ask = alg_sk(sk);
-
-       if (!ask->refcnt) {
-               sock_put(ask->parent);
-               return;
-       }
-
-       af_alg_release_parent(sk);
-}
-
-static void skcipher_sock_destruct_nokey(struct sock *sk)
-{
-       skcipher_sock_destruct_common(sk);
-       skcipher_release_parent_nokey(sk);
-}
-
-static int skcipher_accept_parent_common(void *private, struct sock *sk)
+static int skcipher_accept_parent_nokey(void *private, struct sock *sk)
 {
        struct skcipher_ctx *ctx;
        struct alg_sock *ask = alg_sk(sk);
@@ -981,21 +962,7 @@ static int skcipher_accept_parent(void *private, struct sock *sk)
        if (!tfm->has_key && crypto_skcipher_has_setkey(tfm->skcipher))
                return -ENOKEY;
 
-       return skcipher_accept_parent_common(private, sk);
-}
-
-static int skcipher_accept_parent_nokey(void *private, struct sock *sk)
-{
-       int err;
-
-       err = skcipher_accept_parent_common(private, sk);
-       if (err)
-               goto out;
-
-       sk->sk_destruct = skcipher_sock_destruct_nokey;
-
-out:
-       return err;
+       return skcipher_accept_parent_nokey(private, sk);
 }
 
 static const struct af_alg_type algif_type_skcipher = {