[PATCH 1/2] Bluetooth: virtio_bt: fix leak of vbt on virtio_find_vqs failure

Yi Cong <[email protected]>
Newsgroups org.kernel.vger.linux-bluetooth,org.kernel.vger.stable
Message-ID <[email protected]>
From: Yi Cong <[email protected]>

If virtio_find_vqs() fails, the function returns without freeing the
allocated 'vbt' or clearing 'vdev->priv'.  Add a 'free_priv' label to
release them, and let 'failed' fall through to it.

Fixes: afd2daa26c7a ("Bluetooth: Add support for virtio transport driver")
Cc: [email protected]
Signed-off-by: Yi Cong <[email protected]>
---
 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 c20d54088c8c4..b674fe0c2779e 100644
--- a/drivers/bluetooth/virtio_bt.c
+++ b/drivers/bluetooth/virtio_bt.c
@@ -315,7 +315,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 free_priv;
 
 	hdev = hci_alloc_dev();
 	if (!hdev) {
@@ -404,6 +404,9 @@ static int virtbt_probe(struct virtio_device *vdev)
 	hci_free_dev(hdev);
 failed:
 	vdev->config->del_vqs(vdev);
+free_priv:
+	vdev->priv = NULL;
+	kfree(vbt);
 	return err;
 }
 
-- 
2.25.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.