public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] Bluetooth: hci_sync: Fix not clearing cmd_sync_work_list on power off
@ 2025-04-09 13:54 Luiz Augusto von Dentz
  2025-04-09 13:55 ` Luiz Augusto von Dentz
  2025-04-09 14:34 ` [v1] " bluez.test.bot
  0 siblings, 2 replies; 6+ messages in thread
From: Luiz Augusto von Dentz @ 2025-04-09 13:54 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

When powering off the cmd_sync_work_list may contain items which shall
be cleared during power off as they shouldn't be run during power off
sequence.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
 net/bluetooth/hci_sync.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 609b035e5c90..7a822ef71a74 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -648,16 +648,22 @@ static void _hci_cmd_sync_cancel_entry(struct hci_dev *hdev,
 	kfree(entry);
 }
 
-void hci_cmd_sync_clear(struct hci_dev *hdev)
+/* Clear remaining entries in cmd_sync_work_list */
+static void hci_cmd_sync_list_clear(struct hci_dev *hdev)
 {
 	struct hci_cmd_sync_work_entry *entry, *tmp;
 
+	list_for_each_entry_safe(entry, tmp, &hdev->cmd_sync_work_list, list)
+		_hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED);
+}
+
+void hci_cmd_sync_clear(struct hci_dev *hdev)
+{
 	cancel_work_sync(&hdev->cmd_sync_work);
 	cancel_work_sync(&hdev->reenable_adv_work);
 
 	mutex_lock(&hdev->cmd_sync_work_lock);
-	list_for_each_entry_safe(entry, tmp, &hdev->cmd_sync_work_list, list)
-		_hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED);
+	hci_cmd_sync_list_clear(hdev);
 	mutex_unlock(&hdev->cmd_sync_work_lock);
 }
 
@@ -678,6 +684,7 @@ EXPORT_SYMBOL(hci_cmd_sync_cancel);
  *
  * - Set result and mark status to HCI_REQ_CANCELED
  * - Wakeup command sync thread
+ * - Clear cmd_sync_work_list if the interface is down
  */
 void hci_cmd_sync_cancel_sync(struct hci_dev *hdev, int err)
 {
@@ -692,6 +699,9 @@ void hci_cmd_sync_cancel_sync(struct hci_dev *hdev, int err)
 
 		wake_up_interruptible(&hdev->req_wait_q);
 	}
+
+	if (err == EHOSTDOWN || err == -EHOSTDOWN)
+		hci_cmd_sync_list_clear(hdev);
 }
 EXPORT_SYMBOL(hci_cmd_sync_cancel_sync);
 
@@ -5159,14 +5169,14 @@ int hci_dev_close_sync(struct hci_dev *hdev)
 		disable_delayed_work(&hdev->power_off);
 		disable_delayed_work(&hdev->ncmd_timer);
 		disable_delayed_work(&hdev->le_scan_disable);
+		hci_cmd_sync_cancel_sync(hdev, ENODEV);
 	} else {
 		cancel_delayed_work(&hdev->power_off);
 		cancel_delayed_work(&hdev->ncmd_timer);
 		cancel_delayed_work(&hdev->le_scan_disable);
+		hci_cmd_sync_cancel_sync(hdev, EHOSTDOWN);
 	}
 
-	hci_cmd_sync_cancel_sync(hdev, ENODEV);
-
 	cancel_interleave_scan(hdev);
 
 	if (hdev->adv_instance_timeout) {
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH v1] Bluetooth: hci_sync: Fix not clearing cmd_sync_work_list on power off
@ 2025-12-09 14:03 Shuai Zhang
  2025-12-09 14:40 ` [v1] " bluez.test.bot
  0 siblings, 1 reply; 6+ messages in thread
From: Shuai Zhang @ 2025-12-09 14:03 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz
  Cc: linux-bluetooth, linux-kernel, linux-arm-msm, cheng.jiang,
	quic_chezhou, wei.deng, shuai.zhang

When powering off the cmd_sync_work_list may contain items which shall
be cleared during power off as they shouldn't be run during power off
sequence.

Signed-off-by: Shuai Zhang <shuai.zhang@oss.qualcomm.com>
---
 net/bluetooth/hci_sync.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index a9f5b1a68..45b593ec7 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -648,16 +648,22 @@ static void _hci_cmd_sync_cancel_entry(struct hci_dev *hdev,
 	kfree(entry);
 }
 
-void hci_cmd_sync_clear(struct hci_dev *hdev)
+/* Clear remaining entries in cmd_sync_work_list */
+static void hci_cmd_sync_list_clear(struct hci_dev *hdev)
 {
 	struct hci_cmd_sync_work_entry *entry, *tmp;
 
+	list_for_each_entry_safe(entry, tmp, &hdev->cmd_sync_work_list, list)
+		_hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED);
+}
+
+void hci_cmd_sync_clear(struct hci_dev *hdev)
+{
 	cancel_work_sync(&hdev->cmd_sync_work);
 	cancel_work_sync(&hdev->reenable_adv_work);
 
 	mutex_lock(&hdev->cmd_sync_work_lock);
-	list_for_each_entry_safe(entry, tmp, &hdev->cmd_sync_work_list, list)
-		_hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED);
+	hci_cmd_sync_list_clear(hdev);
 	mutex_unlock(&hdev->cmd_sync_work_lock);
 }
 
@@ -678,6 +684,7 @@ EXPORT_SYMBOL(hci_cmd_sync_cancel);
  *
  * - Set result and mark status to HCI_REQ_CANCELED
  * - Wakeup command sync thread
+ * - Clear cmd_sync_work_list if the interface is down
  */
 void hci_cmd_sync_cancel_sync(struct hci_dev *hdev, int err)
 {
@@ -692,6 +699,9 @@ void hci_cmd_sync_cancel_sync(struct hci_dev *hdev, int err)
 
 		wake_up_interruptible(&hdev->req_wait_q);
 	}
+
+	if (err == EHOSTDOWN || err == -EHOSTDOWN)
+		hci_cmd_sync_list_clear(hdev);
 }
 EXPORT_SYMBOL(hci_cmd_sync_cancel_sync);
 
@@ -5260,14 +5270,14 @@ int hci_dev_close_sync(struct hci_dev *hdev)
 		disable_delayed_work(&hdev->power_off);
 		disable_delayed_work(&hdev->ncmd_timer);
 		disable_delayed_work(&hdev->le_scan_disable);
+		hci_cmd_sync_cancel_sync(hdev, ENODEV);
 	} else {
 		cancel_delayed_work(&hdev->power_off);
 		cancel_delayed_work(&hdev->ncmd_timer);
 		cancel_delayed_work(&hdev->le_scan_disable);
+		hci_cmd_sync_cancel_sync(hdev, EHOSTDOWN);
 	}
 
-	hci_cmd_sync_cancel_sync(hdev, ENODEV);
-
 	cancel_interleave_scan(hdev);
 
 	if (hdev->adv_instance_timeout) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-12-09 14:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-09 13:54 [PATCH v1] Bluetooth: hci_sync: Fix not clearing cmd_sync_work_list on power off Luiz Augusto von Dentz
2025-04-09 13:55 ` Luiz Augusto von Dentz
2025-04-21  5:43   ` Shuai Zhang
2025-05-14  7:39     ` Shuai Zhang
2025-04-09 14:34 ` [v1] " bluez.test.bot
  -- strict thread matches above, loose matches on Subject: below --
2025-12-09 14:03 [PATCH v1] " Shuai Zhang
2025-12-09 14:40 ` [v1] " bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox