* [PATCH v5 1/2] Bluetooth: btusb: mediatek: Fix leaked runtime PM reference in reset
@ 2026-09-04 8:03 Jiajia Liu
2026-09-04 8:03 ` [PATCH v5 2/2] Bluetooth: btusb: Fix leaked runtime PM reference in btusb_reset Jiajia Liu
2026-09-04 16:56 ` [PATCH v5 1/2] Bluetooth: btusb: mediatek: Fix leaked runtime PM reference in reset patchwork-bot+bluetooth
0 siblings, 2 replies; 3+ messages in thread
From: Jiajia Liu @ 2026-09-04 8:03 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz, Ying Hsu, Archie Pusaka,
Abhishek Pandit-Subedi, Matthias Brugger,
AngeloGioacchino Del Regno, Jing Cai, Sean Wang, Chris Lu
Cc: linux-bluetooth, linux-kernel, linux-arm-kernel, linux-mediatek,
Jiajia Liu
MT7925 on HP Pro Mini 260 sometimes timed out during reloading driver
and reset usb device. btusb_suspend is not called again after closing
bluetooth interface.
usbcore: registered new interface driver btusb
Bluetooth: hci0: HW/SW Version: 0x00000000, Build Time: 20260605184935
Bluetooth: hci0: Execution of wmt command timed out
Bluetooth: hci0: Failed to send wmt patch dwnld (-110)
Bluetooth: hci0: Failed to set up firmware (-110)
usb 3-10: reset high-speed USB device number 4 using xhci_hcd
Bluetooth: hci0: HW/SW Version: 0x00000000, Build Time: 20260605184935
Bluetooth: hci0: Device setup in 1856545 usecs
Bluetooth: hci0: AOSP extensions version v1.00
Bluetooth: hci0: AOSP quality report is supported
Bluetooth: MGMT ver 1.23
btusb_mtk_reset calls usb_autopm_get_interface to resume the device
before driving the hardware reset, but never calls the matching
usb_autopm_put_interface. Every hardware reset therefore leaks a PM
usage reference of the interface, preventing the device from being
runtime suspended again until it is unbound.
Add the BTUSB_RESET flag. It is set before usb_queue_reset_device
and is cleared in btusb_disconnect, which drops the reference as well.
If the flag is already set when a new reset is requested, drop one
reference.
Also clear BTMTK_HW_RESET_ACTIVE if usb_autopm_get_interface fails,
otherwise no further reset could ever be attempted.
Fixes: 25b6d7593a3a ("Bluetooth: btmtk: introduce btmtk reset work")
Assisted-by: Claude:qwen3.8-max
Signed-off-by: Jiajia Liu <liujiajia@kylinos.cn>
---
Changes in v5:
- set BTUSB_RESET to 19 since BTUSB_WAKEUP_BROKEN (18) is introduced.
Changes in v4:
- do not return if BTUSB_RESET is set in case the first reset failed.
move test_and_set_bit right before usb_queue_reset_device (sashiko)
Changes in v3:
- rename BTUSB_USB_RESET_ACTIVE to BTUSB_RESET (Luiz)
- test_and_clear_bit BTUSB_RESET in btusb_disconnect (Luiz)
- handle multiple reset requests int btusb_mtk_reset (sashiko)
set BTUSB_RESET if no reset_gpio after usb_autopm_get_interface.
If the flag is already set, add log and drop newly acquired reference
and return.
- clear BTMTK_HW_RESET_ACTIVE if usb_autopm_get_interface fails and add
error log. (sashiko)
Changes in v2:
- Fix the race window (sashiko)
Add and set BTUSB_USB_RESET_ACTIVE flag before usb_queue_reset_device.
Release PM reference in btusb_disconnect if this flag is set.
Changes in v1:
- add usb_autopm_put_interface after usb_queue_reset_device
---
drivers/bluetooth/btusb.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index dfefb43fb792..6f7946709266 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -988,6 +988,7 @@ struct btqca_data {
#define BTUSB_ALT6_CONTINUOUS_TX 16
#define BTUSB_HW_SSR_ACTIVE 17
#define BTUSB_WAKEUP_BROKEN 18
+#define BTUSB_RESET 19
#define BTUSB_PROTO_LEGACY 0x00
#define BTUSB_PROTO_H4 0x01
@@ -3024,8 +3025,11 @@ static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data)
}
err = usb_autopm_get_interface(data->intf);
- if (err < 0)
+ if (err < 0) {
+ bt_dev_err(hdev, "Failed usb_autopm_get_interface: %d", err);
+ clear_bit(BTMTK_HW_RESET_ACTIVE, &btmtk_data->flags);
return err;
+ }
/* Release MediaTek ISO data interface */
btusb_mtk_release_iso_intf(hdev);
@@ -3047,6 +3051,11 @@ static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data)
err = btmtk_usb_subsys_reset(hdev, btmtk_data->dev_id);
+ if (test_and_set_bit(BTUSB_RESET, &data->flags)) {
+ bt_dev_err(hdev, "last usb reset failed? Resetting again");
+ usb_autopm_put_interface_no_suspend(data->intf);
+ }
+
usb_queue_reset_device(data->intf);
clear_bit(BTMTK_HW_RESET_ACTIVE, &btmtk_data->flags);
@@ -4729,6 +4738,9 @@ static void btusb_disconnect(struct usb_interface *intf)
if (data->reset_gpio)
gpiod_put(data->reset_gpio);
+ if (test_and_clear_bit(BTUSB_RESET, &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.55.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v5 2/2] Bluetooth: btusb: Fix leaked runtime PM reference in btusb_reset
2026-09-04 8:03 [PATCH v5 1/2] Bluetooth: btusb: mediatek: Fix leaked runtime PM reference in reset Jiajia Liu
@ 2026-09-04 8:03 ` Jiajia Liu
2026-09-04 16:56 ` [PATCH v5 1/2] Bluetooth: btusb: mediatek: Fix leaked runtime PM reference in reset patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: Jiajia Liu @ 2026-09-04 8:03 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz, Ying Hsu, Archie Pusaka,
Abhishek Pandit-Subedi, Matthias Brugger,
AngeloGioacchino Del Regno, Jing Cai, Sean Wang, Chris Lu
Cc: linux-bluetooth, linux-kernel, linux-arm-kernel, linux-mediatek,
Jiajia Liu
btusb_reset calls usb_autopm_get_interface to resume the device
before queuing a reset of it, but never calls the matching
usb_autopm_put_interface.
usb_queue_reset_device ends up in usb_reset_device(), and since
btusb provides no pre_reset/post_reset callbacks the interface is
merely unbound and rebound: the interface device object survives
this cycle, and so does its PM usage count, which is not cleared
when the driver is unbound.
As a result every reset permanently leaks a PM usage reference,
preventing the interface from being runtime suspended again until
it is unbound.
Set BTUSB_RESET flag before usb_queue_reset_device so that
btusb_disconnect drops the reference. If the flag is already set,
drop one reference.
Fixes: c9209b269afd ("Bluetooth: btusb: Introduce generic USB reset")
Assisted-by: Claude:qwen3.8-max
Signed-off-by: Jiajia Liu <liujiajia@kylinos.cn>
---
Changes in v5:
- no change
Changes in v4:
- do not return if BTUSB_RESET is set in case the first reset failed.
(sashiko)
Changes in v3:
- handle multiple reset requests int btusb_reset (sashiko)
set BTUSB_RESET after usb_autopm_get_interface. If the flag is
already set, drop newly acquired reference and return.
Changes in v2:
- Fix the race window (sashiko)
set BTUSB_USB_RESET_ACTIVE flag before usb_queue_reset_device.
Changes in v1:
- add usb_autopm_put_interface after usb_queue_reset_device
---
drivers/bluetooth/btusb.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 6f7946709266..61c18402911a 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -1068,13 +1068,15 @@ static void btusb_reset(struct hci_dev *hdev)
int err;
data = hci_get_drvdata(hdev);
- /* This is not an unbalanced PM reference since the device will reset */
err = usb_autopm_get_interface(data->intf);
if (err) {
bt_dev_err(hdev, "Failed usb_autopm_get_interface: %d", err);
return;
}
+ if (test_and_set_bit(BTUSB_RESET, &data->flags))
+ usb_autopm_put_interface_no_suspend(data->intf);
+
bt_dev_err(hdev, "Resetting usb device.");
usb_queue_reset_device(data->intf);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v5 1/2] Bluetooth: btusb: mediatek: Fix leaked runtime PM reference in reset
2026-09-04 8:03 [PATCH v5 1/2] Bluetooth: btusb: mediatek: Fix leaked runtime PM reference in reset Jiajia Liu
2026-09-04 8:03 ` [PATCH v5 2/2] Bluetooth: btusb: Fix leaked runtime PM reference in btusb_reset Jiajia Liu
@ 2026-09-04 16:56 ` patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2026-09-04 16:56 UTC (permalink / raw)
To: Jiajia Liu
Cc: marcel, luiz.dentz, yinghsu, apusaka, abhishekpandit,
matthias.bgg, angelogioacchino.delregno, jing.cai, sean.wang,
chris.lu, linux-bluetooth, linux-kernel, linux-arm-kernel,
linux-mediatek
Hello:
This series was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Fri, 4 Sep 2026 16:03:50 +0800 you wrote:
> MT7925 on HP Pro Mini 260 sometimes timed out during reloading driver
> and reset usb device. btusb_suspend is not called again after closing
> bluetooth interface.
>
> usbcore: registered new interface driver btusb
> Bluetooth: hci0: HW/SW Version: 0x00000000, Build Time: 20260605184935
> Bluetooth: hci0: Execution of wmt command timed out
> Bluetooth: hci0: Failed to send wmt patch dwnld (-110)
> Bluetooth: hci0: Failed to set up firmware (-110)
> usb 3-10: reset high-speed USB device number 4 using xhci_hcd
> Bluetooth: hci0: HW/SW Version: 0x00000000, Build Time: 20260605184935
> Bluetooth: hci0: Device setup in 1856545 usecs
> Bluetooth: hci0: AOSP extensions version v1.00
> Bluetooth: hci0: AOSP quality report is supported
> Bluetooth: MGMT ver 1.23
>
> [...]
Here is the summary with links:
- [v5,1/2] Bluetooth: btusb: mediatek: Fix leaked runtime PM reference in reset
https://git.kernel.org/bluetooth/bluetooth-next/c/a78f54e23804
- [v5,2/2] Bluetooth: btusb: Fix leaked runtime PM reference in btusb_reset
https://git.kernel.org/bluetooth/bluetooth-next/c/71729d60938f
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-04 16:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-04 8:03 [PATCH v5 1/2] Bluetooth: btusb: mediatek: Fix leaked runtime PM reference in reset Jiajia Liu
2026-09-04 8:03 ` [PATCH v5 2/2] Bluetooth: btusb: Fix leaked runtime PM reference in btusb_reset Jiajia Liu
2026-09-04 16:56 ` [PATCH v5 1/2] Bluetooth: btusb: mediatek: Fix leaked runtime PM reference in reset patchwork-bot+bluetooth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox