From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Marcel Holtmann <marcel@holtmann.org>,
Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
linux-bluetooth@vger.kernel.org,
linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
Praneeth Balasubramanian <praneethb2002@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH 1/2] Bluetooth: btusb: Use a PM reference during QCA memory dumps
Date: Fri, 4 Dec 2026 10:50:16 -0800 [thread overview]
Message-ID: <20261204185017.1687516-1-praneethb2002@gmail.com> (raw)
handle_dump_pkt_qca() calls usb_disable_autosuspend() when a QCA memory
dump starts and usb_enable_autosuspend() when it ends. Both change the
autosuspend policy that user space sets through power/control, and
their kernel-doc says that the caller must hold the udev device lock.
handle_dump_pkt_qca() runs in the receive path, from URB completion,
where that lock cannot be taken. The enable at the end is also
unconditional: after a dump, autosuspend is on even if the user set
power/control to "on" or loaded btusb with enable_autosuspend=0.
Keep the device awake with a runtime PM reference on the interface
instead, as the reset path does with BTUSB_RESET: take it with
usb_autopm_get_interface_no_resume() when the dump starts and drop it
with usb_autopm_put_interface_no_suspend() when it ends. Both may be
called in atomic context. A new BTUSB_DUMP_AWAKE flag makes sure that
the reference is taken only once, and btusb_disconnect() drops it if a
dump never completed, since the USB core does not reset the usage count
of an unbound interface.
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: 20981ce2d5a5 ("Bluetooth: btusb: Add WCN6855 devcoredump support")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---
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/btusb_main.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/bluetooth/btusb_main.c b/drivers/bluetooth/btusb_main.c
index 95398e2ca098..468415530e3e 100644
--- a/drivers/bluetooth/btusb_main.c
+++ b/drivers/bluetooth/btusb_main.c
@@ -1016,6 +1016,7 @@ struct btqca_data {
#define BTUSB_HW_SSR_ACTIVE 17
#define BTUSB_WAKEUP_BROKEN 18
#define BTUSB_RESET 19
+#define BTUSB_DUMP_AWAKE 20
#define BTUSB_PROTO_LEGACY 0x00
#define BTUSB_PROTO_H4 0x01
@@ -3412,7 +3413,6 @@ static int handle_dump_pkt_qca(struct hci_dev *hdev, struct sk_buff *skb)
struct btusb_data *btdata = hci_get_drvdata(hdev);
struct btqca_data *btqca_data = hci_get_priv(hdev);
struct qca_dump_info *qca_dump_ptr = &btqca_data->qca_dump;
- struct usb_device *udev = btdata->udev;
pkt_type = hci_skb_pkt_type(skb);
skip = sizeof(struct hci_event_hdr);
@@ -3444,7 +3444,12 @@ static int handle_dump_pkt_qca(struct hci_dev *hdev, struct sk_buff *skb)
skb_pull(skb, offsetof(struct qca_dump_hdr, data0));
- usb_disable_autosuspend(udev);
+ /* Keep the device awake until the dump is done. This runs in
+ * URB completion context, so hold a PM reference rather than
+ * change the autosuspend policy, which needs the device lock.
+ */
+ if (!test_and_set_bit(BTUSB_DUMP_AWAKE, &btdata->flags))
+ usb_autopm_get_interface_no_resume(btdata->intf);
bt_dev_info(hdev, "%s memdump size(%u)\n",
(pkt_type == HCI_ACLDATA_PKT) ? "ACL" : "event",
dump_size);
@@ -3482,8 +3487,8 @@ static int handle_dump_pkt_qca(struct hci_dev *hdev, struct sk_buff *skb)
return ret;
out:
- if (qca_dump_ptr->ram_dump_size)
- usb_enable_autosuspend(udev);
+ if (test_and_clear_bit(BTUSB_DUMP_AWAKE, &btdata->flags))
+ usb_autopm_put_interface_no_suspend(btdata->intf);
qca_dump_ptr->ram_dump_size = 0;
qca_dump_ptr->ram_dump_seqno = 0;
clear_bit(BTUSB_HW_SSR_ACTIVE, &btdata->flags);
@@ -4893,6 +4898,10 @@ static void btusb_disconnect(struct usb_interface *intf)
if (test_and_clear_bit(BTUSB_RESET, &data->flags))
usb_autopm_put_interface_no_suspend(data->intf);
+ /* Drop the reference of a firmware dump that did not complete */
+ if (test_and_clear_bit(BTUSB_DUMP_AWAKE, &data->flags))
+ usb_autopm_put_interface_no_suspend(data->intf);
+
if (intf == data->intf) {
if (data->isoc)
usb_driver_release_interface(&btusb_driver, data->isoc);
--
2.25.1
next reply other threads:[~2026-12-04 18:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 18:50 Praneeth Balasubramanian [this message]
2026-12-04 18:50 ` [PATCH 2/2] Bluetooth: btusb: mediatek: Use a PM reference when the firmware dumps Praneeth Balasubramanian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204185017.1687516-1-praneethb2002@gmail.com \
--to=praneethb2002@gmail.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=matthias.bgg@gmail.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox