[PATCH 2/2] Bluetooth: btusb: mediatek: Use a PM reference when the firmware dumps

From: Praneeth Balasubramanian

Date: Fri Dec 04 2026 - 13:50:52 EST


btmtk_usb_recv_acl() calls usb_disable_autosuspend() for every firmware
dump packet (handle 0xfc6f), because a hung firmware can no longer
suspend. usb_disable_autosuspend() changes the autosuspend policy that
user space sets through power/control, and its kernel-doc says that the
caller must hold the udev device lock. btmtk_usb_recv_acl() runs in the
receive path, from URB completion, where that lock cannot be taken.

Keep the device awake with a runtime PM reference on the interface
instead, using the BTUSB_DUMP_AWAKE flag from the previous patch. btusb
now takes the reference on the first dump packet, in a small wrapper
around btmtk_usb_recv_acl(), and btusb_disconnect() drops it when the
device is unbound, for example after a USB reset. As before, the device
stays awake until then, but the user's autosuspend setting is left
alone. btusb is the only user of btmtk_usb_recv_acl().

The missing lock was found by a static check that turns the locking rule
in a function's comment into a Clang context-analysis requirement on its
callers.

Fixes: 0b10c8c84c0c ("Bluetooth: btusb: Record debug log for Mediatek Chip.")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Praneeth Balasubramanian <praneethb2002@xxxxxxxxx>
---

Notes:
This was found by a compiler-based check, part of research at UCSB SecLab.
The locking rule stated in the kernel-doc comment of the called function
was turned into a Clang context-analysis requirement (__must_hold) on that
function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every
caller. An LLM was used only to turn the comment into a machine-readable
rule; the report itself comes from the compiler. The patch and changelog
were drafted with Claude Opus 5.5. I reviewed the patch and take
responsibility for it.

Testing: builds without new warnings with W=1 (x86_64, clang 23,
allmodconfig). Not runtime-tested; I do not have this hardware, and I
have not observed the race myself.

drivers/bluetooth/btmtk.c | 6 +-----
drivers/bluetooth/btusb_main.c | 19 ++++++++++++++++++-
2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c
index 1b3dab0d10bb..d868e7ba4745 100644
--- a/drivers/bluetooth/btmtk.c
+++ b/drivers/bluetooth/btmtk.c
@@ -1439,7 +1439,6 @@ EXPORT_SYMBOL_GPL(btmtk_usb_subsys_reset);

int btmtk_usb_recv_acl(struct hci_dev *hdev, struct sk_buff *skb)
{
- struct btmtk_data *data = hci_get_priv(hdev);
u16 handle = le16_to_cpu(hci_acl_hdr(skb)->handle);

/* The handles below are vendor-reserved values MTK firmware uses to
@@ -1451,10 +1450,7 @@ int btmtk_usb_recv_acl(struct hci_dev *hdev, struct sk_buff *skb)
*/
switch (handle) {
case 0xfc6f: /* Firmware dump from device */
- /* When the firmware hangs, the device can no longer
- * suspend and thus disable auto-suspend.
- */
- usb_disable_autosuspend(data->udev);
+ /* btusb keeps the device awake, see btusb_recv_acl_mtk() */

/* We need to forward the diagnostic packet to userspace daemon
* for backward compatibility, so we have to clone the packet
diff --git a/drivers/bluetooth/btusb_main.c b/drivers/bluetooth/btusb_main.c
index 468415530e3e..088bea4bb594 100644
--- a/drivers/bluetooth/btusb_main.c
+++ b/drivers/bluetooth/btusb_main.c
@@ -3063,6 +3063,23 @@ static void btusb_mtk_release_iso_intf(struct hci_dev *hdev)
clear_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags);
}

+static int btusb_recv_acl_mtk(struct hci_dev *hdev, struct sk_buff *skb)
+{
+ struct btusb_data *data = hci_get_drvdata(hdev);
+
+ /* When the firmware hangs, it sends a dump on handle 0xfc6f and the
+ * device can no longer suspend. Keep it awake until it is reset and
+ * rebound; btusb_disconnect() drops the reference. This runs in URB
+ * completion context, so hold a PM reference rather than change the
+ * autosuspend policy, which needs the device lock.
+ */
+ if (le16_to_cpu(hci_acl_hdr(skb)->handle) == 0xfc6f &&
+ !test_and_set_bit(BTUSB_DUMP_AWAKE, &data->flags))
+ usb_autopm_get_interface_no_resume(data->intf);
+
+ return btmtk_usb_recv_acl(hdev, skb);
+}
+
static int btusb_mtk_disconnect(struct hci_dev *hdev)
{
/* This function describes the specific additional steps taken by MediaTek
@@ -4628,7 +4645,7 @@ static int btusb_probe(struct usb_interface *intf,
hdev->send = btusb_send_frame_mtk;
hci_set_quirk(hdev, HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN);
hci_set_quirk(hdev, HCI_QUIRK_NON_PERSISTENT_SETUP);
- data->recv_acl = btmtk_usb_recv_acl;
+ data->recv_acl = btusb_recv_acl_mtk;
data->recv_event = btmtk_recv_event;
data->suspend = btmtk_usb_suspend;
data->resume = btmtk_usb_resume;
--
2.25.1