From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Marcel Holtmann <marcel@holtmann.org>,
Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: Hans de Goede <hansg@kernel.org>,
linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org,
Praneeth Balasubramanian <praneethb2002@gmail.com>,
stable@vger.kernel.org
Subject: [RFC PATCH] Bluetooth: btusb: Try the device lock when the CSR quirk re-enables autosuspend
Date: Fri, 4 Dec 2026 10:50:10 -0800 [thread overview]
Message-ID: <20261204185010.1687331-1-praneethb2002@gmail.com> (raw)
btusb_setup_csr() ends its workaround for fake CSR controllers by
calling usb_enable_autosuspend() when btusb was loaded with
enable_autosuspend. usb_enable_autosuspend() changes the policy that
user space sets through power/control, and its kernel-doc says that the
caller must hold the udev device lock, which serializes it with writes
to power/control. btusb_setup_csr() runs from the HCI power-on work
without that lock.
A plain usb_lock_device() would deadlock: USB interface drivers are
unbound with the parent device locked, and btusb_disconnect() ->
hci_unregister_dev() waits for the power-on work with
disable_work_sync(). So take the lock with usb_trylock_device(). If it
is busy, which mostly means that the device is going away, leave
autosuspend off and warn; it can still be enabled through power/control.
pm_runtime_allow() and pm_runtime_forbid(), which the workaround calls
before, have no such requirement and are left as they are.
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: 0671c0662383 ("Bluetooth: btusb: Add workaround for remote-wakeup issues with Barrot 8041a02 fake CSR controllers")
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 | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/drivers/bluetooth/btusb_main.c b/drivers/bluetooth/btusb_main.c
index 95398e2ca098..d1d4b9a70606 100644
--- a/drivers/bluetooth/btusb_main.c
+++ b/drivers/bluetooth/btusb_main.c
@@ -2838,9 +2838,19 @@ static int btusb_setup_csr(struct hci_dev *hdev)
device_set_wakeup_capable(&data->udev->dev, false);
- /* Re-enable autosuspend if this was requested */
- if (enable_autosuspend)
- usb_enable_autosuspend(data->udev);
+ /*
+ * Re-enable autosuspend if this was requested. This needs the
+ * device lock, but btusb_disconnect() holds it while it waits
+ * for the power-on work that runs this setup, so only try it.
+ */
+ if (enable_autosuspend) {
+ if (usb_trylock_device(data->udev)) {
+ usb_enable_autosuspend(data->udev);
+ usb_unlock_device(data->udev);
+ } else {
+ bt_dev_warn(hdev, "CSR: Couldn't re-enable autosuspend");
+ }
+ }
}
kfree_skb(skb);
--
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 22:13 ` [RFC] Bluetooth: btusb: Try the device lock when the CSR quirk re-enables autosuspend bluez.test.bot
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=20261204185010.1687331-1-praneethb2002@gmail.com \
--to=praneethb2002@gmail.com \
--cc=hansg@kernel.org \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.