Skip to content

Commit

Permalink
Bluetooth: l2cap: Fix lost wakeups waiting to accept socket
Browse files Browse the repository at this point in the history
Fix race conditions which can cause lost wakeups (or misssed signals)
while waiting to accept an l2cap socket connection.

Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
  • Loading branch information
Peter Hurley authored and Gustavo F. Padovan committed Aug 11, 2011
1 parent 9be4e3f commit f9a3c20
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions net/bluetooth/l2cap_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,39 +235,39 @@ static int l2cap_sock_accept(struct socket *sock, struct socket *newsock, int fl

lock_sock_nested(sk, SINGLE_DEPTH_NESTING);

if (sk->sk_state != BT_LISTEN) {
err = -EBADFD;
goto done;
}

timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);

BT_DBG("sk %p timeo %ld", sk, timeo);

/* Wait for an incoming connection. (wake-one). */
add_wait_queue_exclusive(sk_sleep(sk), &wait);
while (!(nsk = bt_accept_dequeue(sk, newsock))) {
while (1) {
set_current_state(TASK_INTERRUPTIBLE);
if (!timeo) {
err = -EAGAIN;

if (sk->sk_state != BT_LISTEN) {
err = -EBADFD;
break;
}

release_sock(sk);
timeo = schedule_timeout(timeo);
lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
nsk = bt_accept_dequeue(sk, newsock);
if (nsk)
break;

if (sk->sk_state != BT_LISTEN) {
err = -EBADFD;
if (!timeo) {
err = -EAGAIN;
break;
}

if (signal_pending(current)) {
err = sock_intr_errno(timeo);
break;
}

release_sock(sk);
timeo = schedule_timeout(timeo);
lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
}
set_current_state(TASK_RUNNING);
__set_current_state(TASK_RUNNING);
remove_wait_queue(sk_sleep(sk), &wait);

if (err)
Expand Down

0 comments on commit f9a3c20

Please sign in to comment.