struct socket *newsock;
        int rc;
 
-       init_waitqueue_entry(&wait, current);
-
        /*
         * XXX this should add a ref to sock->ops->owner, if
         * TCP could be a module
        rc = sock->ops->accept(sock, newsock, O_NONBLOCK);
        if (rc == -EAGAIN) {
                /* Nothing ready, so wait for activity */
-               set_current_state(TASK_INTERRUPTIBLE);
+               init_waitqueue_entry(&wait, current);
                add_wait_queue(sk_sleep(sock->sk), &wait);
+               set_current_state(TASK_INTERRUPTIBLE);
                schedule();
                remove_wait_queue(sk_sleep(sock->sk), &wait);
-               set_current_state(TASK_RUNNING);
                rc = sock->ops->accept(sock, newsock, O_NONBLOCK);
        }