From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796410248; b=fo7CyOcJzcqidsIo7jAh79n6RsgcIitnWX6cZHUj4BElM0WP64onFq1qocANLzDNhwtA H004gt7ZzW41bQlOOWI9IZYBg7UFLzzI5Adof6MAsWDU9UgjzLjVP2uY4FhXpfuoVcOwd 3V7PRVcw58nhR1sSK05HH8B9FoDKCcx/oWHBD9TXjUGC/Lgoi0Hm9ir/2dYITzM8utVZx z9jA4Mmrfc0Xsf6qX7xLNxihDo8V1f9fWsaG+y1845o2oBp3bAkeVAg0Iy4gjOePiPqt8 Vo//bhbTeSM7y+Z0hDhJkeZTm8VREroabxhUUtzwppX+SSWEm7lqD3K6AmmwFzCkN9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796410248; 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:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=mgHi6BxutEWZ+vXRKNTDwnv2Rgn3qIXZvhYqRTFbqD0=; b=Ty81KtbB9eu4Eu9aagsLupGEJKJdcervTgfQSOnv11lqZC1Z9O1mxh/f0wLnqURd/E4p IWOQ4nJ3XcRjS/gDbkwR+Wops6XZcCtwPRYBYe2G9RRiC7QQF9jGKneRIUqeOaNcjYxCe jTVo3LRMsDX5pHOhVPrcJt5/6tX3YG6GIwLR6e9kM00uBPtSNCv7UFCMEHmn83/MVI7GX 8CqUYNYQsRLmRMNLscSlhnBfIi1j45vbuP2fuORiU0wWdyFtZGHgSNeirD/9TD6MhHc17 Wbp98TrngX1giEcw7y269dRPZ67PtPiDEY4Kzud6818ITcLVPiTJ4P1OaMzB39w47ew== 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=q3IUGMji; arc=none smtp.remote-ip=74.125.82.42 Received: from mail-dl1-f42.google.com (mail-dl1-f42.google.com [74.125.82.42]) (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 18DA2606A32D for ; Fri, 4 Dec 2026 18:50:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 18DA2606A32D 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=q3IUGMji Received: by mail-dl1-f42.google.com with SMTP id a92af1059eb24-170135e43c7so2610459c88.0 for ; Fri, 04 Dec 2026 10:50:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796410247; x=1797015047; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=mgHi6BxutEWZ+vXRKNTDwnv2Rgn3qIXZvhYqRTFbqD0=; b=q3IUGMji/JU4w6W05dc5N+JdQhpJZMjGFp4m2t4o768eDHHoNta1NWI7vFxmwXO2Du IgVw1XGXQRisC9w06ypTEMoyXc05zjL7ZQugn7sC9l8F4B6aPIXCFoE6TUatYYKeEn+X bTOx9+Rdc956C+GKBvmtqfgca0SH88DD45EuSpsj/xydOR8Vrbc/ThW5DSwxOEtBEwO4 unrDXWaZmKbL1u4RjPKGS0k0jZwDyMJgG141sVzEwuBV4PbRVSmLH2UZ0gYT3luCPkxR bNjOU3boD6cMhj2/7XqyXZv8LyKw4NKpOUbFzY2Wad0HxLjOJhHHURnHFlYOUfVqogZx gB9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796410247; x=1797015047; h=content-transfer-encoding:mime-version:references:in-reply-to :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=mgHi6BxutEWZ+vXRKNTDwnv2Rgn3qIXZvhYqRTFbqD0=; b=ITHX3yNL9Ii3H+KL7rAIg0F5LrPOtrwL0gydW8MULGOo2gigYpm4jXjLVOohDK9lIi maJywxjp0ybL1yfCx/sdBwWMULlNWjNcru97Vf/utuco3hnQ2bLIARjdlau187+YZzK+ UHpBKL9D8rnu4zCpHn2L3ILkdADT/quLSORK3pDvpP4updoa2F+SpMp/3zBU3181rSrP KC6A+dE/lBHBjQM3A+q0cCLlhwa7fM738vzTcHYwV59HblAssy73NJffClScZvQO3qj9 Ye8VtdrgDTNF6r9UBl2MgUskG3TnCTFebvRIRqPsJetaWq5MT23JgtXWqaawsQHAw7KG /efA== X-Forwarded-Encrypted: i=1; AL+hErEek05Mq9CeLGejORIozCCSrmaOzED3N5eBf5Yp5Cqp02lwHC8pud8Cq3D+hpNyOXpMWfoE564D3YaTPjw=@vger.kernel.org X-Gm-Message-State: APuU4Z9Qi/CfLoBRj7Yf6vhmgZUY+o4fsj4gJzUhWj/abcKfZsMwzrZz uvP4VWgA4hrUdU7nxEbJAa98zsm8SsAOuS4YzMLuIp1/MI/fEvpyf8Qi X-Gm-Gg: AZFdTZdh+VOuIlVExRzyBoP/WTWJUeqO9996donw1Rgz81mqaRj5IH1+OlmXjv0M1PK EmYR5eu1//oTsbV9Ps+osykgRmQPGazmNBtS571FeiOMfL/H2rRNFAyUUK4XqXeXXk30u82uFTt KfAwNp8cUckrzZ/iDi47QwwnmXCWtyCVkkvBgKR2wjTt2lp9T6/y4D/Aj1BQWoL5Hbt996ZR/SF 5iuXS1Ht6TPahO3CcjtITs0dXl+WVlovfv77ANGqRYxZYXQjtAC2u87qWyNpC0Bq68jcLExIS4p GJraxw9JByWR6VTAf3LPy7ziwRQix3TAl7n505t6RnXXh1od9+lX6A18OgNArm9m65qRbVDrSYe hXZ+JjwOeRwtpxuLHaK7X07vZZR9FXB1GBleQ9lB/GzK1O5/r+V5bdv/mCVfxSEJ2ODMJknS+2t Ub3ZLuC73MKYIl1feg25PWPVHxyRzHsNSVyCtz/JCbAlTNEiWZupOuB7teB9mpqyfeTVNIxnDf/ 1ZdrwzHyUZYLof9meF5t/8Wffz4wkX3ZMJEe7bdKAU+3g5MOrTDqzERA0kAl3pYHfnbembYBPrX UKyBa153Bg0w7P/ygq2/7J6Xp9h7TUjNIy4rTSgGPNAk0AAKJpwCt1ckFj6ZiG7A78cINi+CB8+ +tWUSiFW9ejxtCA== X-Received: by 2002:a05:701a:ccdc:20b0:1b5:b1a2:9873 with SMTP id a92af1059eb24-1b5d7103e17mr2493863c88.25.1796410247220; Fri, 04 Dec 2026 10:50:47 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d644109esm9944981c88.8.2026.12.04.10.50.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 10:50:46 -0800 (PST) From: Praneeth Balasubramanian To: Marcel Holtmann , Luiz Augusto von Dentz Cc: Matthias Brugger , AngeloGioacchino Del Regno , linux-bluetooth@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Praneeth Balasubramanian , stable@vger.kernel.org Subject: [PATCH 2/2] Bluetooth: btusb: mediatek: Use a PM reference when the firmware dumps Date: Fri, 4 Dec 2026 10:50:17 -0800 Message-Id: <20261204185017.1687516-2-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20261204185017.1687516-1-praneethb2002@gmail.com> References: <20261204185017.1687516-1-praneethb2002@gmail.com> X-Mailing-List: linux-kernel@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 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@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/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