mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-24 17:59:32 +00:00
Bluetooth: rfcomm: Fix lost wakeups waiting to accept socket
Fix race conditions which can cause lost wakeups (or missed signals) while waiting to accept an rfcomm socket connection. Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
This commit is contained in:
parent
e5842cdb0f
commit
950e2d51e8
1 changed files with 15 additions and 15 deletions
|
@ -485,11 +485,6 @@ static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock, int f
|
||||||
|
|
||||||
lock_sock(sk);
|
lock_sock(sk);
|
||||||
|
|
||||||
if (sk->sk_state != BT_LISTEN) {
|
|
||||||
err = -EBADFD;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sk->sk_type != SOCK_STREAM) {
|
if (sk->sk_type != SOCK_STREAM) {
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -501,28 +496,33 @@ static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock, int f
|
||||||
|
|
||||||
/* Wait for an incoming connection. (wake-one). */
|
/* Wait for an incoming connection. (wake-one). */
|
||||||
add_wait_queue_exclusive(sk_sleep(sk), &wait);
|
add_wait_queue_exclusive(sk_sleep(sk), &wait);
|
||||||
while (!(nsk = bt_accept_dequeue(sk, newsock))) {
|
while (1) {
|
||||||
set_current_state(TASK_INTERRUPTIBLE);
|
set_current_state(TASK_INTERRUPTIBLE);
|
||||||
if (!timeo) {
|
|
||||||
err = -EAGAIN;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
release_sock(sk);
|
|
||||||
timeo = schedule_timeout(timeo);
|
|
||||||
lock_sock(sk);
|
|
||||||
|
|
||||||
if (sk->sk_state != BT_LISTEN) {
|
if (sk->sk_state != BT_LISTEN) {
|
||||||
err = -EBADFD;
|
err = -EBADFD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsk = bt_accept_dequeue(sk, newsock);
|
||||||
|
if (nsk)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!timeo) {
|
||||||
|
err = -EAGAIN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (signal_pending(current)) {
|
if (signal_pending(current)) {
|
||||||
err = sock_intr_errno(timeo);
|
err = sock_intr_errno(timeo);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
release_sock(sk);
|
||||||
|
timeo = schedule_timeout(timeo);
|
||||||
|
lock_sock(sk);
|
||||||
}
|
}
|
||||||
set_current_state(TASK_RUNNING);
|
__set_current_state(TASK_RUNNING);
|
||||||
remove_wait_queue(sk_sleep(sk), &wait);
|
remove_wait_queue(sk_sleep(sk), &wait);
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
|
|
Loading…
Reference in a new issue