Skip to contentSkip to conversation

Bluetooth: virtio_bt: Fix probe error cleanup

PATCH Applied Yuho Choi 3 participants 3 messages Sep 11 – Sep 15

Subsystems (2)
lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 Bluetooth: virtio_bt: Fix probe error cleanup

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")
---
 drivers/bluetooth/virtio_bt.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/bluetooth/virtio_bt.c +13 -8
index c20d54088c8c..8c55b538deef 100644
@@ -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;
 }
 
Signature · 1 line
2.43.0
#1 lore raw

This is an automated email and please do not reply to this email.

Dear Submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.

----- Output -----

error: patch failed: drivers/bluetooth/virtio_bt.c:315
error: drivers/bluetooth/virtio_bt.c: patch does not apply
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"

Please resolve the issue and submit the patches again.

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Yuho Choi
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 10 lines · On Thu, 10 Sep 2026 22:41:24 -0400 you wrote:

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.

[...]

Here is the summary with links:
- [v1] Bluetooth: virtio_bt: Fix probe error cleanup

    https://git.kernel.org/bluetooth/bluetooth-next/c/8ec80e64922f

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html