diff options
| -rw-r--r-- | net/bluetooth/hci_sync.c | 64 |
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); |
