rfcomm, sched/wait: Fix broken wait construct
authorPeter Zijlstra <[email protected]>
Wed, 29 Oct 2014 15:17:12 +0000 (16:17 +0100)
committerIngo Molnar <[email protected]>
Tue, 4 Nov 2014 06:17:47 +0000 (07:17 +0100)
rfcomm_run() is a tad broken in that is has a nested wait loop. One
cannot rely on p->state for the outer wait because the inner wait will
overwrite it.

Fix this using the new wait_woken() facility.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Cc: Peter Hurley <[email protected]>
Cc: Alexander Holler <[email protected]>
Cc: David S. Miller <[email protected]>
Cc: Gustavo Padovan <[email protected]>
Cc: Joe Perches <[email protected]>
Cc: Johan Hedberg <[email protected]>
Cc: Libor Pechacek <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Marcel Holtmann <[email protected]>
Cc: Seung-Woo Kim <[email protected]>
Cc: Vignesh Raman <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Ingo Molnar <[email protected]>
net/bluetooth/rfcomm/core.c

index af73bc3acb406a6256565a18d0ddf2611a96e07f..410dd5e76c41bff9111f6c32fbf8aff536974ddd 100644 (file)
@@ -101,11 +101,11 @@ static struct rfcomm_session *rfcomm_session_del(struct rfcomm_session *s);
 #define __get_rpn_stop_bits(line) (((line) >> 2) & 0x1)
 #define __get_rpn_parity(line)    (((line) >> 3) & 0x7)
 
+static DECLARE_WAIT_QUEUE_HEAD(rfcomm_wq);
+
 static void rfcomm_schedule(void)
 {
-       if (!rfcomm_thread)
-               return;
-       wake_up_process(rfcomm_thread);
+       wake_up_all(&rfcomm_wq);
 }
 
 /* ---- RFCOMM FCS computation ---- */
@@ -2086,24 +2086,22 @@ static void rfcomm_kill_listener(void)
 
 static int rfcomm_run(void *unused)
 {
+       DEFINE_WAIT_FUNC(wait, woken_wake_function);
        BT_DBG("");
 
        set_user_nice(current, -10);
 
        rfcomm_add_listener(BDADDR_ANY);
 
-       while (1) {
-               set_current_state(TASK_INTERRUPTIBLE);
-
-               if (kthread_should_stop())
-                       break;
+       add_wait_queue(&rfcomm_wq, &wait);
+       while (!kthread_should_stop()) {
 
                /* Process stuff */
                rfcomm_process_sessions();
 
-               schedule();
+               wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
        }
-       __set_current_state(TASK_RUNNING);
+       remove_wait_queue(&rfcomm_wq, &wait);
 
        rfcomm_kill_listener();