Commit 5c912495 authored by Marcel Holtmann's avatar Marcel Holtmann

Bluetooth: Introduce hci_dev_do_reset helper function

Split the hci_dev_reset ioctl handling into using hci_dev_do_reset
helper function. Similar to what has been done with hci_dev_do_open
and hci_dev_do_close.
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent 8f502f84
...@@ -1719,32 +1719,14 @@ int hci_dev_close(__u16 dev) ...@@ -1719,32 +1719,14 @@ int hci_dev_close(__u16 dev)
return err; return err;
} }
int hci_dev_reset(__u16 dev) static int hci_dev_do_reset(struct hci_dev *hdev)
{ {
struct hci_dev *hdev; int ret;
int ret = 0;
hdev = hci_dev_get(dev); BT_DBG("%s %p", hdev->name, hdev);
if (!hdev)
return -ENODEV;
hci_req_lock(hdev); hci_req_lock(hdev);
if (!test_bit(HCI_UP, &hdev->flags)) {
ret = -ENETDOWN;
goto done;
}
if (test_bit(HCI_USER_CHANNEL, &hdev->dev_flags)) {
ret = -EBUSY;
goto done;
}
if (test_bit(HCI_UNCONFIGURED, &hdev->dev_flags)) {
ret = -EOPNOTSUPP;
goto done;
}
/* Drop queues */ /* Drop queues */
skb_queue_purge(&hdev->rx_q); skb_queue_purge(&hdev->rx_q);
skb_queue_purge(&hdev->cmd_q); skb_queue_purge(&hdev->cmd_q);
...@@ -1767,12 +1749,41 @@ int hci_dev_reset(__u16 dev) ...@@ -1767,12 +1749,41 @@ int hci_dev_reset(__u16 dev)
ret = __hci_req_sync(hdev, hci_reset_req, 0, HCI_INIT_TIMEOUT); ret = __hci_req_sync(hdev, hci_reset_req, 0, HCI_INIT_TIMEOUT);
done:
hci_req_unlock(hdev); hci_req_unlock(hdev);
hci_dev_put(hdev);
return ret; return ret;
} }
int hci_dev_reset(__u16 dev)
{
struct hci_dev *hdev;
int err;
hdev = hci_dev_get(dev);
if (!hdev)
return -ENODEV;
if (!test_bit(HCI_UP, &hdev->flags)) {
err = -ENETDOWN;
goto done;
}
if (test_bit(HCI_USER_CHANNEL, &hdev->dev_flags)) {
err = -EBUSY;
goto done;
}
if (test_bit(HCI_UNCONFIGURED, &hdev->dev_flags)) {
err = -EOPNOTSUPP;
goto done;
}
err = hci_dev_do_reset(hdev);
done:
hci_dev_put(hdev);
return err;
}
int hci_dev_reset_stat(__u16 dev) int hci_dev_reset_stat(__u16 dev)
{ {
struct hci_dev *hdev; struct hci_dev *hdev;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment