diff mbox series

[v2] Bluetooth: hci_core: fix error handling in hci_register_dev()

Message ID 20221019080652.836484-1-yangyingliang@huawei.com
State Superseded
Headers show
Series [v2] Bluetooth: hci_core: fix error handling in hci_register_dev() | expand

Commit Message

Yang Yingliang Oct. 19, 2022, 8:06 a.m. UTC
If hci_register_suspend_notifier() returns error, the hdev
need to be put and deleted and rfkill need be unregistered
and destroyed to avoid leaks.

Fixes: 9952d90ea288 ("Bluetooth: Handle PM_SUSPEND_PREPARE and PM_POST_SUSPEND")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
v1 -> v2:
  Add rfkill_destroy().
---
 net/bluetooth/hci_core.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 0540555b3704..a6222238de7f 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2660,7 +2660,7 @@  int hci_register_dev(struct hci_dev *hdev)
 
 	error = hci_register_suspend_notifier(hdev);
 	if (error)
-		goto err_wqueue;
+		goto err_hdev;
 
 	queue_work(hdev->req_workqueue, &hdev->power_on);
 
@@ -2669,6 +2669,14 @@  int hci_register_dev(struct hci_dev *hdev)
 
 	return id;
 
+err_hdev:
+	hci_dev_put(hdev);
+	if (hdev->rfkill) {
+		rfkill_unregister(hdev->rfkill);
+		rfkill_destroy(hdev->rfkill);
+		hdev->rfkill = NULL;
+	}
+	device_del(&hdev->dev);
 err_wqueue:
 	debugfs_remove_recursive(hdev->debugfs);
 	destroy_workqueue(hdev->workqueue);