* [PATCH] Bluetooth: HCI: Fix hci0 not release in usb disconnect process
@ 2026-03-18 2:57 zhangchen200426
2026-03-18 4:41 ` bluez.test.bot
0 siblings, 1 reply; 2+ messages in thread
From: zhangchen200426 @ 2026-03-18 2:57 UTC (permalink / raw)
To: luiz.von.dentz, pav, pmenzel, kuniyu, yang.li, kees, ceggers,
marcel
Cc: linux-bluetooth, Zhang Chen
From: Zhang Chen <zhangchen01@kylinos.cn>
If hci_resume_dev before hci_unregister_dev, the hci command will
timeout and the reference count of hdev will not reset to zero.
Then the node "hci0" will not release.
The output in question is as follows:
Bluetooth: hci0: command 0x0c01 tx timeout
Bluetooth: hci0: Opcode 0x0c01 failed: -110
Bluetooth: hci0: command 0x0c01 tx timeout
Bluetooth: hci0: Opcode 0x0c1a failed: -110
usb 10-1: new full-speed USB device number 95 using xhci-hcd
usb 10-1: Product: Bluetooth Radio
usb 10-1: Manufacturer: Realtek
usb 10-1: SerialNumber: 00e04c000001
Bluetooth: hci1: RTL: rom_version status=0 version=1
Bluetooth: hci1: RTL: loading rtl_bt/rtl8852bu_fw.bin
Bluetooth: hci1: RTL: loading rtl_bt/rtl8852bu_config.bin
Bluetooth: hci1: RTL: cfg_sz 6, total sz 65603
The call sequence in question is as follows:
usb disconnect:
btusb_disconnect
hci_unregister_dev
hci_dev_set_flag
hci_cmd_sync_clear
hci_unregister_suspend_notifier
hci_dev_do_close
device_del
device resume:
hci_suspend_notifier
hci_resume_dev
hci_resume_sync
hci_set_event_mask_sync
__hci_cmd_sync_status
__hci_cmd_sync_status_sk
__hci_cmd_sync_sk
wait_event_interruptible_timeout
This patch add hci_cancel_cmd_sync in hci_unregister_dev to wake up
hdev->req_wait_q, and stop __hci_cmd_sync_sk by judging the
HCI_UNREGISTER flag. Then stopping hci_resume_dev process based on the
returned error code.
Fixes: 182ee45da083 ("Bluetooth: hci_sync: Rework hci_suspend_notifier")
Cc: linux-bluetooth@vger.kernel.org
Signed-off-by: Zhang Chen <zhangchen01@kylinos.cn>
---
net/bluetooth/hci_core.c | 6 ++++++
net/bluetooth/hci_sync.c | 22 ++++++++++++++++------
2 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 22598581b1ad..c6238a69a0d5 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -50,6 +50,7 @@
static void hci_rx_work(struct work_struct *work);
static void hci_cmd_work(struct work_struct *work);
static void hci_tx_work(struct work_struct *work);
+static void hci_cancel_cmd_sync(struct hci_dev *hdev, int err);
/* HCI device list */
LIST_HEAD(hci_dev_list);
@@ -2696,6 +2697,8 @@ void hci_unregister_dev(struct hci_dev *hdev)
hci_dev_set_flag(hdev, HCI_UNREGISTER);
mutex_unlock(&hdev->unregister_lock);
+ hci_cancel_cmd_sync(hdev, EINTR);
+
write_lock(&hci_dev_list_lock);
list_del(&hdev->list);
write_unlock(&hci_dev_list_lock);
@@ -2878,6 +2881,9 @@ int hci_resume_dev(struct hci_dev *hdev)
ret = hci_resume_sync(hdev);
hci_req_sync_unlock(hdev);
+ if (ret && hci_dev_test_flag(hdev, HCI_UNREGISTER))
+ return 0;
+
mgmt_resuming(hdev, hdev->wake_reason, &hdev->wake_addr,
hdev->wake_addr_type);
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 3166914b0d6c..ac4c973dd976 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -174,10 +174,11 @@ struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen,
return ERR_PTR(err);
err = wait_event_interruptible_timeout(hdev->req_wait_q,
- hdev->req_status != HCI_REQ_PEND,
+ hdev->req_status != HCI_REQ_PEND ||
+ hci_dev_test_flag(hdev, HCI_UNREGISTER),
timeout);
- if (err == -ERESTARTSYS)
+ if (err == -ERESTARTSYS || hci_dev_test_flag(hdev, HCI_UNREGISTER))
return ERR_PTR(-EINTR);
switch (hdev->req_status) {
@@ -6346,6 +6347,7 @@ static int hci_resume_scan_sync(struct hci_dev *hdev)
*/
int hci_resume_sync(struct hci_dev *hdev)
{
+ int err;
/* If not marked as suspended there nothing to do */
if (!hdev->suspended)
return 0;
@@ -6353,10 +6355,14 @@ int hci_resume_sync(struct hci_dev *hdev)
hdev->suspended = false;
/* Restore event mask */
- hci_set_event_mask_sync(hdev);
+ err = hci_set_event_mask_sync(hdev);
+ if (err && hci_dev_test_flag(hdev, HCI_UNREGISTER))
+ return err;
/* Clear any event filters and restore scan state */
- hci_clear_event_filter_sync(hdev);
+ err = hci_clear_event_filter_sync(hdev);
+ if (err && hci_dev_test_flag(hdev, HCI_UNREGISTER))
+ return err;
/* Resume scanning */
hci_resume_scan_sync(hdev);
@@ -6365,10 +6371,14 @@ int hci_resume_sync(struct hci_dev *hdev)
hci_resume_monitor_sync(hdev);
/* Resume other advertisements */
- hci_resume_advertising_sync(hdev);
+ err = hci_resume_advertising_sync(hdev);
+ if (err && hci_dev_test_flag(hdev, HCI_UNREGISTER))
+ return err;
/* Resume discovery */
- hci_resume_discovery_sync(hdev);
+ err = hci_resume_discovery_sync(hdev);
+ if (err && hci_dev_test_flag(hdev, HCI_UNREGISTER))
+ return err;
return 0;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* RE: Bluetooth: HCI: Fix hci0 not release in usb disconnect process
2026-03-18 2:57 [PATCH] Bluetooth: HCI: Fix hci0 not release in usb disconnect process zhangchen200426
@ 2026-03-18 4:41 ` bluez.test.bot
0 siblings, 0 replies; 2+ messages in thread
From: bluez.test.bot @ 2026-03-18 4:41 UTC (permalink / raw)
To: linux-bluetooth, zhangchen200426
[-- Attachment #1: Type: text/plain, Size: 3101 bytes --]
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1068376
---Test result---
Test Summary:
CheckPatch PENDING 0.54 seconds
GitLint PENDING 0.26 seconds
SubjectPrefix PASS 0.08 seconds
BuildKernel PASS 26.72 seconds
CheckAllWarning PASS 29.14 seconds
CheckSparse PASS 28.28 seconds
BuildKernel32 PASS 26.13 seconds
TestRunnerSetup PASS 571.61 seconds
TestRunner_l2cap-tester FAIL 29.12 seconds
TestRunner_iso-tester FAIL 28.16 seconds
TestRunner_bnep-tester PASS 6.27 seconds
TestRunner_mgmt-tester FAIL 115.22 seconds
TestRunner_rfcomm-tester PASS 9.43 seconds
TestRunner_sco-tester FAIL 12.39 seconds
TestRunner_ioctl-tester PASS 10.31 seconds
TestRunner_mesh-tester FAIL 12.46 seconds
TestRunner_smp-tester PASS 8.50 seconds
TestRunner_userchan-tester PASS 6.67 seconds
IncrementalBuild PENDING 0.94 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: TestRunner_l2cap-tester - FAIL
Desc: Run l2cap-tester with test-runner
Output:
Total: 96, Passed: 95 (99.0%), Failed: 1, Not Run: 0
Failed Test Cases
L2CAP BR/EDR Server - Set PHY 1M Failed 0.120 seconds
##############################
Test: TestRunner_iso-tester - FAIL
Desc: Run iso-tester with test-runner
Output:
BUG: KASAN: slab-use-after-free in le_read_features_complete+0x7e/0x2b0
Total: 141, Passed: 141 (100.0%), Failed: 0, Not Run: 0
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 494, Passed: 489 (99.0%), Failed: 1, Not Run: 4
Failed Test Cases
Read Exp Feature - Success Failed 0.110 seconds
##############################
Test: TestRunner_sco-tester - FAIL
Desc: Run sco-tester with test-runner
Output:
WARNING: possible circular locking dependency detected
BUG: sleeping function called from invalid context at net/core/sock.c:3782
Total: 30, Passed: 30 (100.0%), Failed: 0, Not Run: 0
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner
Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0
Failed Test Cases
Mesh - Send cancel - 1 Timed out 2.781 seconds
Mesh - Send cancel - 2 Timed out 1.995 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-18 4:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-18 2:57 [PATCH] Bluetooth: HCI: Fix hci0 not release in usb disconnect process zhangchen200426
2026-03-18 4:41 ` bluez.test.bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox