Lee, Chun-Yi a82f6f
From: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>
Lee, Chun-Yi a82f6f
Date: Tue, 26 Apr 2022 11:18:23 +0300
Lee, Chun-Yi a82f6f
Subject: Bluetooth: core: Fix missing power_on work cancel on HCI close
Lee, Chun-Yi a82f6f
Patch-mainline: v5.19-rc1
Lee, Chun-Yi a82f6f
Git-commit: ff7f2926114d3a50f5ffe461a9bce8d761748da5
Lee, Chun-Yi a82f6f
References: jsc#PED-1407
Lee, Chun-Yi a82f6f
Lee, Chun-Yi a82f6f
Move power_on work cancel to hci_dev_close_sync to ensure that power_on
Lee, Chun-Yi a82f6f
work is canceled after HCI interface down, power off, rfkill, etc.
Lee, Chun-Yi a82f6f
Lee, Chun-Yi a82f6f
For example, if
Lee, Chun-Yi a82f6f
Lee, Chun-Yi a82f6f
    hciconfig hci0 down
Lee, Chun-Yi a82f6f
Lee, Chun-Yi a82f6f
is done early enough during boot, it may run before power_on work.
Lee, Chun-Yi a82f6f
Then, power_on work will actually bring up interface despite above
Lee, Chun-Yi a82f6f
hciconfig command.
Lee, Chun-Yi a82f6f
Lee, Chun-Yi a82f6f
Signed-off-by: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>
Lee, Chun-Yi a82f6f
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Lee, Chun-Yi a82f6f
Acked-by: Lee, Chun-Yi <jlee@suse.com>
Lee, Chun-Yi a82f6f
---
Lee, Chun-Yi a82f6f
 net/bluetooth/hci_core.c |    2 --
Lee, Chun-Yi a82f6f
 net/bluetooth/hci_sync.c |    1 +
Lee, Chun-Yi a82f6f
 2 files changed, 1 insertion(+), 2 deletions(-)
Lee, Chun-Yi a82f6f
Lee, Chun-Yi a82f6f
--- a/net/bluetooth/hci_core.c
Lee, Chun-Yi a82f6f
+++ b/net/bluetooth/hci_core.c
Lee, Chun-Yi a82f6f
@@ -2675,8 +2675,6 @@ void hci_unregister_dev(struct hci_dev *
Lee, Chun-Yi a82f6f
 	list_del(&hdev->list);
Lee, Chun-Yi a82f6f
 	write_unlock(&hci_dev_list_lock);
Lee, Chun-Yi a82f6f
 
Lee, Chun-Yi a82f6f
-	cancel_work_sync(&hdev->power_on);
Lee, Chun-Yi a82f6f
-
Lee, Chun-Yi a82f6f
 	hci_cmd_sync_clear(hdev);
Lee, Chun-Yi a82f6f
 
Lee, Chun-Yi a82f6f
 	if (!test_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks))
Lee, Chun-Yi a82f6f
--- a/net/bluetooth/hci_sync.c
Lee, Chun-Yi a82f6f
+++ b/net/bluetooth/hci_sync.c
Lee, Chun-Yi a82f6f
@@ -4089,6 +4089,7 @@ int hci_dev_close_sync(struct hci_dev *h
Lee, Chun-Yi a82f6f
 
Lee, Chun-Yi a82f6f
 	bt_dev_dbg(hdev, "");
Lee, Chun-Yi a82f6f
 
Lee, Chun-Yi a82f6f
+	cancel_work_sync(&hdev->power_on);
Lee, Chun-Yi a82f6f
 	cancel_delayed_work(&hdev->power_off);
Lee, Chun-Yi a82f6f
 	cancel_delayed_work(&hdev->ncmd_timer);
Lee, Chun-Yi a82f6f