Linux bluetooth development
 help / color / mirror / Atom feed
From: Zhao Dongdong <winter91@foxmail.com>
To: marcel@holtmann.org, luiz.dentz@gmail.com
Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org,
	Zhao Dongdong <zhaodongdong@kylinos.cn>
Subject: [PATCH] Bluetooth: virtio_bt: fix memory leak in virtbt_probe
Date: Thu,  9 Jul 2026 09:57:50 +0800	[thread overview]
Message-ID: <tencent_EC14979976A7BBA1E2B79B3F5116F7C30C07@qq.com> (raw)

From: Zhao Dongdong <zhaodongdong@kylinos.cn>

In virtbt_probe(), the vbt structure is allocated via kzalloc_obj()
but not freed when virtio_find_vqs() fails. Additionally, the
open_failed and failed error labels do not free vbt, causing a
memory leak on any error path after vbt allocation.

Fix the leak by adding a dedicated err_find_vqs label after del_vqs
in the failed path, so that find_vqs failures skip del_vqs (since
vqs were never established) while still freeing vbt. The existing
failed and open_failed labels also gain vbt cleanup.

Fixes: afd2daa26c7a ("Bluetooth: Add support for virtio transport driver")
Signed-off-by: Zhao Dongdong <zhaodongdong@kylinos.cn>
---
 drivers/bluetooth/virtio_bt.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c
index 140ab55c9fc5..61ab3863bb0f 100644
--- a/drivers/bluetooth/virtio_bt.c
+++ b/drivers/bluetooth/virtio_bt.c
@@ -311,7 +311,7 @@ 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 find_vqs_failed;
 
 	hdev = hci_alloc_dev();
 	if (!hdev) {
@@ -400,6 +400,9 @@ static int virtbt_probe(struct virtio_device *vdev)
 	hci_free_dev(hdev);
 failed:
 	vdev->config->del_vqs(vdev);
+find_vqs_failed:
+	vdev->priv = NULL;
+	kfree(vbt);
 	return err;
 }
 
-- 
2.25.1


             reply	other threads:[~2026-07-09  1:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09  1:57 Zhao Dongdong [this message]
2026-07-09  5:34 ` Bluetooth: virtio_bt: fix memory leak in virtbt_probe bluez.test.bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_EC14979976A7BBA1E2B79B3F5116F7C30C07@qq.com \
    --to=winter91@foxmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=zhaodongdong@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox