Skip to content

Commit 6107122

Browse files
committed
Bluetooth: btusb: Don't fail external suspend requests
Commit 4e0a1d8 ("Bluetooth: btusb: Don't suspend when there are connections") introduces a check for connections to prevent auto-suspend but that actually ignored the fact the .suspend callback can be called for external suspend requests which Documentation/driver-api/usb/power-management.rst states the following: 'External suspend calls should never be allowed to fail in this way, only autosuspend calls. The driver can tell them apart by applying the :c:func:`PMSG_IS_AUTO` macro to the message argument to the ``suspend`` method; it will return True for internal PM events (autosuspend) and False for external PM events.' In addition to that align system suspend with USB suspend by using hci_suspend_dev since otherwise the stack would be expecting events such as advertising reports which may not be delivered while the transport is suspended. Fixes: 4e0a1d8 ("Bluetooth: btusb: Don't suspend when there are connections") Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Tested-by: Kiran K <kiran.k@intel.com>
1 parent 18fd04a commit 6107122

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

drivers/bluetooth/btusb.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4038,23 +4038,37 @@ static void btusb_disconnect(struct usb_interface *intf)
40384038
static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
40394039
{
40404040
struct btusb_data *data = usb_get_intfdata(intf);
4041+
int err;
40414042

40424043
BT_DBG("intf %p", intf);
40434044

4044-
/* Don't suspend if there are connections */
4045-
if (hci_conn_count(data->hdev))
4045+
/* Don't auto-suspend if there are connections; external suspend calls
4046+
* shall never fail.
4047+
*/
4048+
if (PMSG_IS_AUTO(message) && hci_conn_count(data->hdev))
40464049
return -EBUSY;
40474050

40484051
if (data->suspend_count++)
40494052
return 0;
40504053

4054+
/* Notify Host stack to suspend; this has to be done before stopping
4055+
* the traffic since the hci_suspend_dev itself may generate some
4056+
* traffic.
4057+
*/
4058+
err = hci_suspend_dev(data->hdev);
4059+
if (err) {
4060+
data->suspend_count--;
4061+
return err;
4062+
}
4063+
40514064
spin_lock_irq(&data->txlock);
40524065
if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) {
40534066
set_bit(BTUSB_SUSPENDING, &data->flags);
40544067
spin_unlock_irq(&data->txlock);
40554068
} else {
40564069
spin_unlock_irq(&data->txlock);
40574070
data->suspend_count--;
4071+
hci_resume_dev(data->hdev);
40584072
return -EBUSY;
40594073
}
40604074

@@ -4175,6 +4189,8 @@ static int btusb_resume(struct usb_interface *intf)
41754189
spin_unlock_irq(&data->txlock);
41764190
schedule_work(&data->work);
41774191

4192+
hci_resume_dev(data->hdev);
4193+
41784194
return 0;
41794195

41804196
failed:

0 commit comments

Comments
 (0)