summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans de Goede <johannes.goede@oss.qualcomm.com>2026-08-11 10:37:30 +0200
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2026-09-15 15:43:51 -0400
commit2123877dec9bd09c7a6afce08df2b4d21db2af96 (patch)
tree64bc44a9fe151af9f696ecff291ab0acb2c91d54
parent801fb950cae7048eb7d83b18857d1ca37b8cd5a4 (diff)
downloadlinux-next-2123877dec9bd09c7a6afce08df2b4d21db2af96.tar.gz
linux-next-2123877dec9bd09c7a6afce08df2b4d21db2af96.zip
Bluetooth: hci_sync: Factor common cleanup code into a helper
The hci_dev_init_sync() failure path in hci_dev_open_sync() and the cleanup code in hci_dev_close_sync() have a bunch of common code. Factor this duplicate code out into a hci_dev_drop_last_cmd_req_and_close() helper function. Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
-rw-r--r--net/bluetooth/hci_sync.c64
1 files changed, 27 insertions, 37 deletions
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 74e2b04c84b2..00be55cf60ac 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -5376,6 +5376,30 @@ static int hci_dev_init_sync(struct hci_dev *hdev)
return ret;
}
+static void hci_dev_drop_last_cmd_req_and_close(struct hci_dev *hdev)
+{
+ /* Drop last sent command */
+ if (hdev->sent_cmd) {
+ cancel_delayed_work_sync(&hdev->cmd_timer);
+ kfree_skb(hdev->sent_cmd);
+ hdev->sent_cmd = NULL;
+ }
+
+ /* Drop last request */
+ if (hdev->req_skb) {
+ kfree_skb(hdev->req_skb);
+ hdev->req_skb = NULL;
+ hci_dev_clear_flag(hdev, HCI_CMD_PENDING);
+ }
+
+ clear_bit(HCI_RUNNING, &hdev->flags);
+ hci_sock_dev_event(hdev, HCI_DEV_CLOSE);
+
+ /* After this point our queues are empty and no tasks are scheduled. */
+ hdev->close(hdev);
+ hdev->flags &= BIT(HCI_RAW);
+}
+
int hci_dev_open_sync(struct hci_dev *hdev)
{
int ret;
@@ -5462,23 +5486,7 @@ int hci_dev_open_sync(struct hci_dev *hdev)
if (hdev->flush)
hdev->flush(hdev);
- if (hdev->sent_cmd) {
- cancel_delayed_work_sync(&hdev->cmd_timer);
- kfree_skb(hdev->sent_cmd);
- hdev->sent_cmd = NULL;
- }
-
- if (hdev->req_skb) {
- kfree_skb(hdev->req_skb);
- hdev->req_skb = NULL;
- hci_dev_clear_flag(hdev, HCI_CMD_PENDING);
- }
-
- clear_bit(HCI_RUNNING, &hdev->flags);
- hci_sock_dev_event(hdev, HCI_DEV_CLOSE);
-
- hdev->close(hdev);
- hdev->flags &= BIT(HCI_RAW);
+ hci_dev_drop_last_cmd_req_and_close(hdev);
}
done:
@@ -5645,28 +5653,10 @@ int hci_dev_close_sync(struct hci_dev *hdev)
skb_queue_purge(&hdev->cmd_q);
skb_queue_purge(&hdev->raw_q);
- /* Drop last sent command */
- if (hdev->sent_cmd) {
- cancel_delayed_work_sync(&hdev->cmd_timer);
- kfree_skb(hdev->sent_cmd);
- hdev->sent_cmd = NULL;
- }
-
- /* Drop last request */
- if (hdev->req_skb) {
- kfree_skb(hdev->req_skb);
- hdev->req_skb = NULL;
- hci_dev_clear_flag(hdev, HCI_CMD_PENDING);
- }
-
- clear_bit(HCI_RUNNING, &hdev->flags);
- hci_sock_dev_event(hdev, HCI_DEV_CLOSE);
-
- /* After this point our queues are empty and no tasks are scheduled. */
- hdev->close(hdev);
+ /* Drop last sent command, last request and close */
+ hci_dev_drop_last_cmd_req_and_close(hdev);
/* Clear flags */
- hdev->flags &= BIT(HCI_RAW);
hci_dev_clear_volatile_flags(hdev);
hci_dev_clear_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE);