* [PATCH] Bluetooth: btusb: free skb and setup packet of deferred TX URBs
@ 2026-11-30 6:47 Bilal Yazıcıoğlu
2026-11-30 16:27 ` bluez.test.bot
2026-11-30 20:00 ` [PATCH] " patchwork-bot+bluetooth
0 siblings, 2 replies; 3+ messages in thread
From: Bilal Yazıcıoğlu @ 2026-11-30 6:47 UTC (permalink / raw)
To: linux-bluetooth
Cc: Marcel Holtmann, Luiz Augusto von Dentz, linux-kernel,
Bilal Yazıcıoğlu
While the adapter is runtime suspended, submit_or_queue_tx_urb() does
not submit TX URBs but anchors them on data->deferred, so that
play_deferred() submits them on resume. Until then the driver owns the
skb in urb->context and the control request in urb->setup_packet,
which are normally freed by the completion handlers.
When these URBs are dropped instead of submitted, only the URB itself
is freed:
- btusb_close() and the failed path of btusb_resume() discard them
with usb_scuttle_anchored_urbs(), leaking both the skb and the
setup packet.
- play_deferred() frees the setup packet but not the skb, both when
usb_submit_urb() fails and for the URBs left on the anchor after
that.
On a ThinkPad T480 (Intel 8265, 8087:0a2b) this happens every time
Bluetooth is switched off from the desktop while the adapter is
autosuspended. thinkpad_acpi cuts power to the USB device, the
HCI_Reset sent by btintel_shutdown_combined() gets deferred, the
resume in btusb_close() fails and the queued command is dropped:
usb 1-7: USB disconnect, device number 25
Bluetooth: hci0: HCI reset during shutdown failed
Bluetooth: hci0: Error when powering off device on rfkill (-19)
kmemleak reports three objects per toggle (skb head, skb data and the
8 byte setup packet, 880 bytes in total), allocated from
hci_cmd_sync_alloc() and alloc_ctrl_urb().
Add btusb_free_deferred(), which frees the setup packet, the skb and
the URB of every URB on the deferred anchor, and use it in
btusb_close(), btusb_resume() and play_deferred(). Also free the skb
when usb_submit_urb() fails in play_deferred().
Tested on a ThinkPad T480 with KASAN, kmemleak and lockdep enabled,
switching Bluetooth off and on through blueman 10 times per run:
30 objects leaked without this patch and none with it, in two runs.
There were no KASAN or lockdep reports, and suspend/resume and Wi-Fi
rfkill kept working. Only the btusb_close() path was exercised; the
btusb_resume() and play_deferred() changes are covered by code
inspection only.
I ran a debug kernel with kmemleak on my ThinkPad T480 together with
Claude Code, which ran the tests and found the leak. It also helped
with the analysis and this changelog. I wrote the fix and reviewed the
analysis and the test results.
Fixes: 7bee549e197c ("Bluetooth: Add USB autosuspend support to btusb driver")
Fixes: 7b8e2c1db0f3 ("fix memory leak in fixed btusb_close")
Fixes: 19cfe912c37b ("Bluetooth: btusb: Fix memory leak in play_deferred")
Signed-off-by: Bilal Yazıcıoğlu <ahmetbilalyazicioglu@gmail.com>
---
drivers/bluetooth/btusb_main.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/drivers/bluetooth/btusb_main.c b/drivers/bluetooth/btusb_main.c
index 95398e2ca..12396ed93 100644
--- a/drivers/bluetooth/btusb_main.c
+++ b/drivers/bluetooth/btusb_main.c
@@ -2122,6 +2122,18 @@ static void btusb_isoc_tx_complete(struct urb *urb)
kfree_skb(skb);
}
+static void btusb_free_deferred(struct btusb_data *data)
+{
+ struct urb *urb;
+
+ /* Deferred URBs were never submitted, so their completion won't run. */
+ while ((urb = usb_get_from_anchor(&data->deferred))) {
+ kfree(urb->setup_packet);
+ kfree_skb(urb->context);
+ usb_free_urb(urb);
+ }
+}
+
static int btusb_open(struct hci_dev *hdev)
{
struct btusb_data *data = hci_get_drvdata(hdev);
@@ -2235,7 +2247,7 @@ static int btusb_close(struct hci_dev *hdev)
usb_autopm_put_interface(data->intf);
failed:
- usb_scuttle_anchored_urbs(&data->deferred);
+ btusb_free_deferred(data);
return 0;
}
@@ -5000,6 +5012,7 @@ static void play_deferred(struct btusb_data *data)
BT_ERR("%s urb %p submission failed (%d)",
data->hdev->name, urb, -err);
kfree(urb->setup_packet);
+ kfree_skb(urb->context);
usb_unanchor_urb(urb);
usb_free_urb(urb);
break;
@@ -5010,10 +5023,7 @@ static void play_deferred(struct btusb_data *data)
}
/* Cleanup the rest deferred urbs. */
- while ((urb = usb_get_from_anchor(&data->deferred))) {
- kfree(urb->setup_packet);
- usb_free_urb(urb);
- }
+ btusb_free_deferred(data);
}
static int btusb_resume(struct usb_interface *intf)
@@ -5073,7 +5083,7 @@ static int btusb_resume(struct usb_interface *intf)
return 0;
failed:
- usb_scuttle_anchored_urbs(&data->deferred);
+ btusb_free_deferred(data);
done:
spin_lock_irq(&data->txlock);
clear_bit(BTUSB_SUSPENDING, &data->flags);
--
2.56.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: Bluetooth: btusb: free skb and setup packet of deferred TX URBs
2026-11-30 6:47 [PATCH] Bluetooth: btusb: free skb and setup packet of deferred TX URBs Bilal Yazıcıoğlu
@ 2026-11-30 16:27 ` bluez.test.bot
2026-11-30 20:00 ` [PATCH] " patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2026-11-30 16:27 UTC (permalink / raw)
To: linux-bluetooth, ahmetbilalyazicioglu
[-- Attachment #1: Type: text/plain, Size: 1020 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/1226369/
---Test result---
Test Summary:
CheckPatch PASS 0.40 seconds
VerifyFixes PASS 0.05 seconds
VerifySignedoff PASS 0.05 seconds
GitLint PASS 0.15 seconds
SubjectPrefix PASS 0.04 seconds
BuildKernel PASS 20.71 seconds
CheckAllWarning PASS 23.39 seconds
CheckSparse PASS 25.05 seconds
BuildKernel32 PASS 20.96 seconds
CheckKernelLLVM PASS 22.93 seconds
TestRunnerSetup PASS 486.21 seconds
IncrementalBuild PASS 19.65 seconds
https://github.com/bluez/bluetooth-next/pull/1252
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Bluetooth: btusb: free skb and setup packet of deferred TX URBs
2026-11-30 6:47 [PATCH] Bluetooth: btusb: free skb and setup packet of deferred TX URBs Bilal Yazıcıoğlu
2026-11-30 16:27 ` bluez.test.bot
@ 2026-11-30 20:00 ` patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2026-11-30 20:00 UTC (permalink / raw)
To: =?utf-8?q?Bilal_Yaz=C4=B1c=C4=B1o=C4=9Flu_=3Cahmetbilalyazicioglu=40gmail=2E?=,
=?utf-8?q?com=3E?=
Cc: linux-bluetooth, marcel, luiz.dentz, linux-kernel
Hello:
This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Mon, 30 Nov 2026 09:47:51 +0300 you wrote:
> While the adapter is runtime suspended, submit_or_queue_tx_urb() does
> not submit TX URBs but anchors them on data->deferred, so that
> play_deferred() submits them on resume. Until then the driver owns the
> skb in urb->context and the control request in urb->setup_packet,
> which are normally freed by the completion handlers.
>
> When these URBs are dropped instead of submitted, only the URB itself
> is freed:
>
> [...]
Here is the summary with links:
- Bluetooth: btusb: free skb and setup packet of deferred TX URBs
https://git.kernel.org/bluetooth/bluetooth-next/c/0aed540213bb
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-11-30 20:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 6:47 [PATCH] Bluetooth: btusb: free skb and setup packet of deferred TX URBs Bilal Yazıcıoğlu
2026-11-30 16:27 ` bluez.test.bot
2026-11-30 20:00 ` [PATCH] " 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