[PATCH v1] Bluetooth: virtio_bt: Fix probe error cleanup
From: Yuho Choi
Date: Thu Sep 10 2026 - 22:42:09 EST
Once hci_register_dev() succeeds, the HCI device is published, a
registration reference is held, and power-on work is queued. If
virtbt_open_vdev() fails, the error path only drops the caller's
reference before deleting the virtqueues.
The registration reference keeps the HCI device and its callbacks alive.
Therefore, a later HCI send can dereference a freed virtqueue through
vbt->vqs.
Unregister the HCI device to withdraw it and drain its work before
resetting the virtio device, reclaiming queued buffers, and deleting the
virtqueues. Also, free vbt on every probe error path.
Fixes: afd2daa26c7a ("Bluetooth: Add support for virtio transport driver")
Fixes: dc65b4b0f90a ("Bluetooth: virtio_bt: fix device removal")
Cc: stable@xxxxxxxxxxxxxxx # 6.2+
Signed-off-by: Yuho Choi <oss.patchbox@xxxxxxxxx>
---
drivers/bluetooth/virtio_bt.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c
index c20d54088c8c..8c55b538deef 100644
--- a/drivers/bluetooth/virtio_bt.c
+++ b/drivers/bluetooth/virtio_bt.c
@@ -315,12 +315,12 @@ static int virtbt_probe(struct virtio_device *vdev)
err = virtio_find_vqs(vdev, VIRTBT_NUM_VQS, vbt->vqs, vqs_info, NULL);
if (err)
- return err;
+ goto err_free_vbt;
hdev = hci_alloc_dev();
if (!hdev) {
err = -ENOMEM;
- goto failed;
+ goto err_del_vqs;
}
vbt->hdev = hdev;
@@ -390,20 +390,25 @@ static int virtbt_probe(struct virtio_device *vdev)
if (hci_register_dev(hdev) < 0) {
hci_free_dev(hdev);
err = -EBUSY;
- goto failed;
+ goto err_del_vqs;
}
virtio_device_ready(vdev);
err = virtbt_open_vdev(vbt);
- if (err)
- goto open_failed;
+ if (err) {
+ hci_unregister_dev(hdev);
+ virtio_reset_device(vdev);
+ virtbt_close_vdev(vbt);
+ hci_free_dev(hdev);
+ goto err_del_vqs;
+ }
return 0;
-open_failed:
- hci_free_dev(hdev);
-failed:
+err_del_vqs:
vdev->config->del_vqs(vdev);
+err_free_vbt:
+ kfree(vbt);
return err;
}
--
2.43.0