Skip to content

Commit 8731840

Browse files
apanditholtmann
authored andcommitted
Bluetooth: Restore running state if suspend fails
If Bluetooth fails to enter the suspended state correctly, restore the state to running (re-enabling scans). PM_POST_SUSPEND is only sent to notifiers that successfully return from PM_PREPARE_SUSPEND notification so we should recover gracefully if it fails. Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 0d7043f commit 8731840

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

‎net/bluetooth/hci_core.c‎

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3305,6 +3305,15 @@ static void hci_prepare_suspend(struct work_struct *work)
33053305
hci_dev_unlock(hdev);
33063306
}
33073307

3308+
static int hci_change_suspend_state(struct hci_dev *hdev,
3309+
enum suspended_state next)
3310+
{
3311+
hdev->suspend_state_next = next;
3312+
set_bit(SUSPEND_PREPARE_NOTIFIER, hdev->suspend_tasks);
3313+
queue_work(hdev->req_workqueue, &hdev->suspend_prepare);
3314+
return hci_suspend_wait_event(hdev);
3315+
}
3316+
33083317
static int hci_suspend_notifier(struct notifier_block *nb, unsigned long action,
33093318
void *data)
33103319
{
@@ -3330,32 +3339,24 @@ static int hci_suspend_notifier(struct notifier_block *nb, unsigned long action,
33303339
* connectable (disabling scanning)
33313340
* - Second, program event filter/whitelist and enable scan
33323341
*/
3333-
hdev->suspend_state_next = BT_SUSPEND_DISCONNECT;
3334-
set_bit(SUSPEND_PREPARE_NOTIFIER, hdev->suspend_tasks);
3335-
queue_work(hdev->req_workqueue, &hdev->suspend_prepare);
3336-
ret = hci_suspend_wait_event(hdev);
3342+
ret = hci_change_suspend_state(hdev, BT_SUSPEND_DISCONNECT);
33373343

3338-
/* If the disconnect portion failed, don't attempt to complete
3339-
* by configuring the whitelist. The suspend notifier will
3340-
* follow a cancelled suspend with a PM_POST_SUSPEND
3341-
* notification.
3342-
*/
3343-
if (!ret) {
3344-
hdev->suspend_state_next = BT_SUSPEND_COMPLETE;
3345-
set_bit(SUSPEND_PREPARE_NOTIFIER, hdev->suspend_tasks);
3346-
queue_work(hdev->req_workqueue, &hdev->suspend_prepare);
3347-
ret = hci_suspend_wait_event(hdev);
3348-
}
3344+
/* Only configure whitelist if disconnect succeeded */
3345+
if (!ret)
3346+
ret = hci_change_suspend_state(hdev,
3347+
BT_SUSPEND_COMPLETE);
33493348
} else if (action == PM_POST_SUSPEND) {
3350-
hdev->suspend_state_next = BT_RUNNING;
3351-
set_bit(SUSPEND_PREPARE_NOTIFIER, hdev->suspend_tasks);
3352-
queue_work(hdev->req_workqueue, &hdev->suspend_prepare);
3353-
ret = hci_suspend_wait_event(hdev);
3349+
ret = hci_change_suspend_state(hdev, BT_RUNNING);
33543350
}
33553351

3352+
/* If suspend failed, restore it to running */
3353+
if (ret && action == PM_SUSPEND_PREPARE)
3354+
hci_change_suspend_state(hdev, BT_RUNNING);
3355+
33563356
done:
33573357
return ret ? notifier_from_errno(-EBUSY) : NOTIFY_STOP;
33583358
}
3359+
33593360
/* Alloc HCI device */
33603361
struct hci_dev *hci_alloc_dev(void)
33613362
{

0 commit comments

Comments
 (0)