Phonet: allow multiple listen() and fix small race condition
authorRémi Denis-Courmont <remi.denis-courmont@nokia.com>
Thu, 24 Feb 2011 23:14:56 +0000 (23:14 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 25 Feb 2011 19:19:34 +0000 (11:19 -0800)
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/phonet/socket.c

index 25f746d20c1f2dcbf42826cf33f07a35e44ace1c..ceb5143f5ef9e483af171940885abc94dc85ee57 100644 (file)
@@ -428,19 +428,19 @@ static int pn_socket_listen(struct socket *sock, int backlog)
        struct sock *sk = sock->sk;
        int err = 0;
 
-       if (sock->state != SS_UNCONNECTED)
-               return -EINVAL;
        if (pn_socket_autobind(sock))
                return -ENOBUFS;
 
        lock_sock(sk);
-       if (sk->sk_state != TCP_CLOSE) {
+       if (sock->state != SS_UNCONNECTED) {
                err = -EINVAL;
                goto out;
        }
 
-       sk->sk_state = TCP_LISTEN;
-       sk->sk_ack_backlog = 0;
+       if (sk->sk_state != TCP_LISTEN) {
+               sk->sk_state = TCP_LISTEN;
+               sk->sk_ack_backlog = 0;
+       }
        sk->sk_max_ack_backlog = backlog;
 out:
        release_sock(sk);