Linux bluetooth development
 help / color / mirror / Atom feed
* [RFC PATCH] Bluetooth: btusb: Try the device lock when the CSR quirk re-enables autosuspend
@ 2026-12-04 18:50 Praneeth Balasubramanian
  2026-12-04 22:13 ` [RFC] " bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-04 18:50 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz
  Cc: Hans de Goede, linux-bluetooth, linux-kernel,
	Praneeth Balasubramanian, stable

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: [RFC] Bluetooth: btusb: Try the device lock when the CSR quirk re-enables autosuspend
  2026-12-04 18:50 [RFC PATCH] Bluetooth: btusb: Try the device lock when the CSR quirk re-enables autosuspend Praneeth Balasubramanian
@ 2026-12-04 22:13 ` bluez.test.bot
  0 siblings, 0 replies; 2+ messages in thread
From: bluez.test.bot @ 2026-12-04 22:13 UTC (permalink / raw)
  To: linux-bluetooth, praneethb2002

[-- Attachment #1: Type: text/plain, Size: 1365 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/series/1232337/

---Test result---

Test Summary:
CheckPatch                    PASS      0.51 seconds
VerifyFixes                   PASS      0.09 seconds
VerifySignedoff               PASS      0.10 seconds
GitLint                       FAIL      0.24 seconds
SubjectPrefix                 PASS      0.09 seconds
BuildKernel                   PASS      17.82 seconds
CheckAllWarning               PASS      20.36 seconds
CheckSparse                   PASS      22.34 seconds
BuildKernel32                 PASS      18.07 seconds
CheckKernelLLVM               PASS      18.23 seconds
TestRunnerSetup               PASS      407.04 seconds
IncrementalBuild              PASS      16.97 seconds

Details
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[RFC] Bluetooth: btusb: Try the device lock when the CSR quirk re-enables autosuspend

1: T1 Title exceeds max length (85>80): "[RFC] Bluetooth: btusb: Try the device lock when the CSR quirk re-enables autosuspend"
38: B2 Line has trailing whitespace: "    "


https://github.com/bluez/bluetooth-next/pull/1289

---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04 22:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 18:50 [RFC PATCH] Bluetooth: btusb: Try the device lock when the CSR quirk re-enables autosuspend Praneeth Balasubramanian
2026-12-04 22:13 ` [RFC] " 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