mirror of
https://github.com/torvalds/linux.git
synced 2026-11-10 17:11:02 +01:00
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>
This commit is contained in:
parent
05b5019b01
commit
8b431b664d
|
|
@ -5390,6 +5390,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;
|
||||
|
|
@ -5476,23 +5500,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:
|
||||
|
|
@ -5659,28 +5667,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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user