Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc4445c7 authored by Andre Guedes's avatar Andre Guedes Committed by Gustavo Padovan
Browse files

Bluetooth: Fix __hci_req_sync



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: default avatarAndre Guedes <andre.guedes@openbossa.org>
Acked-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
Signed-off-by: default avatarGustavo Padovan <gustavo.padovan@collabora.co.uk>
parent d865b007
Loading
Loading
Loading
Loading
+3 −4
Original line number Original line Diff line number Diff line
@@ -95,15 +95,11 @@ static int __hci_req_sync(struct hci_dev *hdev,


	hdev->req_status = HCI_REQ_PEND;
	hdev->req_status = HCI_REQ_PEND;


	add_wait_queue(&hdev->req_wait_q, &wait);
	set_current_state(TASK_INTERRUPTIBLE);

	func(&req, opt);
	func(&req, opt);


	err = hci_req_run(&req, hci_req_sync_complete);
	err = hci_req_run(&req, hci_req_sync_complete);
	if (err < 0) {
	if (err < 0) {
		hdev->req_status = 0;
		hdev->req_status = 0;
		remove_wait_queue(&hdev->req_wait_q, &wait);
		/* req_run will fail if the request did not add any
		/* req_run will fail if the request did not add any
		 * commands to the queue, something that can happen when
		 * commands to the queue, something that can happen when
		 * a request with conditionals doesn't trigger any
		 * a request with conditionals doesn't trigger any
@@ -113,6 +109,9 @@ static int __hci_req_sync(struct hci_dev *hdev,
		return 0;
		return 0;
	}
	}


	add_wait_queue(&hdev->req_wait_q, &wait);
	set_current_state(TASK_INTERRUPTIBLE);

	schedule_timeout(timeout);
	schedule_timeout(timeout);


	remove_wait_queue(&hdev->req_wait_q, &wait);
	remove_wait_queue(&hdev->req_wait_q, &wait);