Bluetooth: Fix __hci_req_sync
authorAndre Guedes <[email protected]>
Fri, 8 Mar 2013 14:20:13 +0000 (11:20 -0300)
committerGustavo Padovan <[email protected]>
Sat, 9 Mar 2013 20:10:13 +0000 (17:10 -0300)
If hci_req_run returns error, we erroneously leave the current
process in TASK_INTERRUPTABLE state. If we leave the process in
TASK_INTERRUPTABLE and it is preempted, this process will never
be scheduled again.

This patch fixes this issue by moving the preparation for scheduling
(add to waitqueue and set process state) to just after the hci_req_run
call.

Signed-off-by: Andre Guedes <[email protected]>
Acked-by: Johan Hedberg <[email protected]>
Signed-off-by: Gustavo Padovan <[email protected]>
net/bluetooth/hci_core.c

index 3fc699db8fb5a7c75350212197bb7f8659c24c1e..5c64398472868acd2efbed56db78053b168a23e5 100644 (file)
@@ -95,15 +95,11 @@ static int __hci_req_sync(struct hci_dev *hdev,
 
        hdev->req_status = HCI_REQ_PEND;
 
-       add_wait_queue(&hdev->req_wait_q, &wait);
-       set_current_state(TASK_INTERRUPTIBLE);
-
        func(&req, opt);
 
        err = hci_req_run(&req, hci_req_sync_complete);
        if (err < 0) {
                hdev->req_status = 0;
-               remove_wait_queue(&hdev->req_wait_q, &wait);
                /* req_run will fail if the request did not add any
                 * commands to the queue, something that can happen when
                 * a request with conditionals doesn't trigger any
@@ -113,6 +109,9 @@ static int __hci_req_sync(struct hci_dev *hdev,
                return 0;
        }
 
+       add_wait_queue(&hdev->req_wait_q, &wait);
+       set_current_state(TASK_INTERRUPTIBLE);
+
        schedule_timeout(timeout);
 
        remove_wait_queue(&hdev->req_wait_q, &wait);