[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251031081525.2275894-1-lilinmao@kylinos.cn>
Date: Fri, 31 Oct 2025 16:15:25 +0800
From: Linmao Li <lilinmao@...inos.cn>
To: linux-bluetooth@...r.kernel.org
Cc: marcel@...tmann.org,
luiz.dentz@...il.com,
linux-kernel@...r.kernel.org,
Linmao Li <lilinmao@...inos.cn>
Subject: [PATCH] Bluetooth: btusb: Prevent autosuspend when le_scan_disable work is pending
When USB autosuspend occurs while le_scan_disable work is scheduled,
HCI commands sent by the work fail with timeout, leaving LE scan in
an inconsistent state.
Scenario:
T=0: LE scan starts, le_scan_disable work queued (+10240ms)
T=8s: Autosuspend check: tx_in_flight=0, suspend proceeds
T=10s: le_scan_disable work executes on suspended device
→ HCI command 0x2042 times out
The tx_in_flight check only protects actively transmitted URBs, missing
the window where work is queued but hasn't submitted its URB yet.
Fix by checking delayed_work_pending(&hdev->le_scan_disable) during
autosuspend. Return -EBUSY if pending to block suspend until work
completes. Only set BTUSB_SUSPENDING after all checks pass to avoid
leaving the flag set if suspend is aborted.
Signed-off-by: Linmao Li <lilinmao@...inos.cn>
---
drivers/bluetooth/btusb.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 5e9ebf0c5312..a344ea1dc466 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -4389,6 +4389,7 @@ static void btusb_disconnect(struct usb_interface *intf)
static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
{
struct btusb_data *data = usb_get_intfdata(intf);
+ struct hci_dev *hdev = data->hdev;
BT_DBG("intf %p", intf);
@@ -4402,14 +4403,19 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
return 0;
spin_lock_irq(&data->txlock);
- if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) {
- set_bit(BTUSB_SUSPENDING, &data->flags);
- spin_unlock_irq(&data->txlock);
- } else {
+ if (PMSG_IS_AUTO(message) && data->tx_in_flight) {
spin_unlock_irq(&data->txlock);
data->suspend_count--;
return -EBUSY;
}
+ spin_unlock_irq(&data->txlock);
+
+ if (PMSG_IS_AUTO(message) && delayed_work_pending(&hdev->le_scan_disable)) {
+ data->suspend_count--;
+ return -EBUSY;
+ }
+
+ set_bit(BTUSB_SUSPENDING, &data->flags);
cancel_work_sync(&data->work);
--
2.25.1
Powered by blists - more mailing lists