Skip to content

Commit e1c7a44

Browse files
JeffyCNgregkh
authored andcommitted
Bluetooth: bnep: fix possible might sleep error in bnep_session
commit 25717382c1dd0ddced2059053e3ca5088665f7a5 upstream. It looks like bnep_session has same pattern as the issue reported in old rfcomm: while (1) { set_current_state(TASK_INTERRUPTIBLE); if (condition) break; // may call might_sleep here schedule(); } __set_current_state(TASK_RUNNING); Which fixed at: dfb2fae Bluetooth: Fix nested sleeps So let's fix it at the same way, also follow the suggestion of: https://lwn.net/Articles/628628/ Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> Reviewed-by: Brian Norris <briannorris@chromium.org> Reviewed-by: AL Yu-Chen Cho <acho@suse.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Cc: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f9adf42 commit e1c7a44

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

net/bluetooth/bnep/core.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,16 +484,16 @@ static int bnep_session(void *arg)
484484
struct net_device *dev = s->dev;
485485
struct sock *sk = s->sock->sk;
486486
struct sk_buff *skb;
487-
wait_queue_t wait;
487+
DEFINE_WAIT_FUNC(wait, woken_wake_function);
488488

489489
BT_DBG("");
490490

491491
set_user_nice(current, -15);
492492

493-
init_waitqueue_entry(&wait, current);
494493
add_wait_queue(sk_sleep(sk), &wait);
495494
while (1) {
496-
set_current_state(TASK_INTERRUPTIBLE);
495+
/* Ensure session->terminate is updated */
496+
smp_mb__before_atomic();
497497

498498
if (atomic_read(&s->terminate))
499499
break;
@@ -515,9 +515,8 @@ static int bnep_session(void *arg)
515515
break;
516516
netif_wake_queue(dev);
517517

518-
schedule();
518+
wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
519519
}
520-
__set_current_state(TASK_RUNNING);
521520
remove_wait_queue(sk_sleep(sk), &wait);
522521

523522
/* Cleanup session */
@@ -663,7 +662,7 @@ int bnep_del_connection(struct bnep_conndel_req *req)
663662
s = __bnep_get_session(req->dst);
664663
if (s) {
665664
atomic_inc(&s->terminate);
666-
wake_up_process(s->task);
665+
wake_up_interruptible(sk_sleep(s->sock->sk));
667666
} else
668667
err = -ENOENT;
669668

0 commit comments

Comments
 (0)