From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796410214; b=2riSU6dWqAlOQ5H4xoPgJI5uN8OudjwyWk8NazBS4caWXLcDjYrnGx7D4XopPg/8z3DP Yv51gGdvfajOotU9CLh50IxMj8NzXXlczwqXH18WcRCn1xf789XiVRV4G7LN+wDmwGbIF Goy+RJl9MITHzmlGQqMFNg++p2PccaKRSqUbdh+ImhrNbgADvnZj+6YHXKfyx/vfRXhSy Pkj8krBoRnDs3+45JQS6+WfCFvAM0yyYXEDrUisRWQPiTG/iVycbQMiT/QOSGLL97R4NO 5RyKt9UoUa7qzfKXslOX3Ta+Wd4qDLoAkrqjU0L6EMW3M+UlecEuWRPyc4q3qu6H4EQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796410214; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=vyPHiQ7cAPiiOLkFkxaEwM4NKC2d7VCOnb3h/HFuAF8=; b=G0ODMgj1q2sIQX1lkP4bXCN4mrkfgq1FPf1BvrRD3kedd2/42y2tMm9rEeDDuX2/pB1L GxZYZAlEhW6mKO8XLo88bQNS6NaztYEl0gNTk1fMnbeJaNcYhAZ3FxT6wqn2UN9M5CbqO c3VbOuyT7Mlha6hxXc8CSeWx12tnYkeel/nEihBoEFGq722mH3o8woaYs9aZh5q+LrSji 0qDD1OSdm1FEUg5OcwYv5Owj07fbwSseqgtzdHRALS0GYb7vhXKzaBAAKdi1czDpWFRfK t5iXxc3Yb3AJuMOL1NEe9YXTDO6nXv5Tpn5VOiWO/9YQvz0eyadPvEDmENzC7SEU3Tw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0M38+OyW; arc=none smtp.remote-ip=74.125.82.53 Received: from mail-dl1-f53.google.com (mail-dl1-f53.google.com [74.125.82.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CD5D606A334 for ; Fri, 4 Dec 2026 18:50:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0CD5D606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0M38+OyW Received: by mail-dl1-f53.google.com with SMTP id a92af1059eb24-1b546061d58so2932681c88.1 for ; Fri, 04 Dec 2026 10:50:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796410213; x=1797015013; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=vyPHiQ7cAPiiOLkFkxaEwM4NKC2d7VCOnb3h/HFuAF8=; b=0M38+OyW6YWyYhdf8G34F50eKyyBFkO1RftPYS0UbZEgG2PSbt3Uqk8yyxtoh+upvq yiGjsI/XagH8h8FGPqYxyWTRAcnwDzmNVpVOrjAttRhl7JIjiia+NeZfW3JfqgBuVpC8 vn9QRf16vkG8rr3NPzx6UGbF8QD9h1jovDq65P48cuL57S9aU/RgXiN6M6SAjCBZYfUy 04Iy02Y6fo/DDk08mVZgyi3KtPS73yCDEUHIPU59awPddBZsQev+CQ4OWYaiSa6zOG+6 sdmYQFSwRz8QlairvuqBApa7JwHPmo3l8MIfwAgNr1Bl6NGr13+VjgRejGfuQCmRkpGE hkvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796410213; x=1797015013; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=vyPHiQ7cAPiiOLkFkxaEwM4NKC2d7VCOnb3h/HFuAF8=; b=qXpon1P0nnilSAKTR3rRypvxXsMpQNYut9D9Jzsb8VVShCGxfNTjHBSOvrIRRIyJLM HOE+GCVcepu0SPjQhTOQj4qahf3j6tsDQjEIo/wfyACdwud3lDSS8gWhGIovLrQ0Sitn fXBVmcRZvCFIT6v2BK0Zgt9uG+Otcfwi/ECLdlApIgwzvTQQ5fxp2RuPBVIoADP0yVsb I+cx8gW2R9Ch6X8FiqJTza2pnktxthu/IAMTwPRQ3hRjxM3oypE7ctNzIerYrdX/Xa/6 /duyhKh1Av4sov436nxihv63LwhokXRad3LBJDEQBcHDQMXWEMBU/qZ36bmnUBlYVkMP sanA== X-Forwarded-Encrypted: i=1; AL+hErGzq+mDicPRS0wuVddht/jfgmUFRZet1HX/SdKRD6hxRyMy3vOBdDRU9xXg10TQGLb93ShuwYC8WQ7CiiUnSm0=@vger.kernel.org X-Gm-Message-State: APuU4Z+9VXBmEXWkbEdDtwpK6DHKOrVIF2kfPtALmCKopv4VV4b/irmr /P/cilvJGc+Xf7VqUY3RaPOiHALRQk71RZ6wRnamSdErZ+XUT5YorXDW X-Gm-Gg: AZFdTZeJcEDNOI7tYo7+YcMy/c0PSLSRqATZhjEjwNsgP1nsZicSLV3FOafQdyjvHhX tuxAvmJ0c2tMw/liBqkN/sggEExhlOqpPWCz1Xyv+EfjCr2K0kTEqcjEvVcamCQlANGuQj9bSo0 M1WBh7G9NKfDlS4FDTLlBzw3ASFF0tdmeAH1DV7rrqvGR0yoxnxYNoOr4J9BXg9BOU7ESLbMO62 t8nQp+6h+rygBIrJDqMPXSoPhjCSySgCwrpuOSm087N+MUq9DdAfbHEkvx/SJoZ7Z0gOEoUDUtC FSJplkRtZLO5sW9a4JGXC5YxELua4X0f4a2RfaayP1NdevyvY5hztVPUIY6ZATy/NjOPhpwesjP OtiQ2x7Ta3t9kSvSk9T7n+tKHwWSxcxgzUs6wPsPFH4uthHqIxVmxodEAMGKZji5GB2FZaUkkPP cuIYVo0psAeFJr6/zQFznIxOM8bXocrSR0fCIBgtYtBj7Vk4vvG7VM4OTnb0OzAnIS+QsviUqHX ilwoGMK1MiumWH7/WTYiXtRQ36ko6ks61JCjj2a8kNcms6j7Ri3x9cv/OXRdH2OyHEj2ML586PO SY2QTqG6UhoGww1yBLoXDpbb/CEe3kw7VDWR5NckQ5XkA1xqgeKr0Y/a9lgeWhyiuYg= X-Received: by 2002:a05:701a:c9db:20b0:1b5:c305:2f6d with SMTP id a92af1059eb24-1b5d70cc875mr2728947c88.7.1796410213069; Fri, 04 Dec 2026 10:50:13 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d642e254sm9316253c88.4.2026.12.04.10.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 10:50:12 -0800 (PST) From: Praneeth Balasubramanian To: Marcel Holtmann , Luiz Augusto von Dentz Cc: Hans de Goede , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, Praneeth Balasubramanian , 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 Message-Id: <20261204185010.1687331-1-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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