Bluetooth: Move discoverable timeout behind hdev->req_workqueue
authorJohan Hedberg <johan.hedberg@intel.com>
Mon, 23 Nov 2015 13:43:06 +0000 (15:43 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 9 Dec 2015 23:51:48 +0000 (00:51 +0100)
Since the other discoverable changes are behind req_workqueue now it
only makes sense to move the discoverable timeout there as well.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
include/net/bluetooth/hci_core.h
net/bluetooth/hci_core.c
net/bluetooth/hci_request.c
net/bluetooth/mgmt.c

index 0a6966ed7ee109bbf224e6212992073e1a5acfca..319bf020cea65ceb5c45dd5d5d187ce521323452 100644 (file)
@@ -1436,7 +1436,6 @@ void mgmt_index_added(struct hci_dev *hdev);
 void mgmt_index_removed(struct hci_dev *hdev);
 void mgmt_set_powered_failed(struct hci_dev *hdev, int err);
 int mgmt_powered(struct hci_dev *hdev, u8 powered);
-void mgmt_discoverable_timeout(struct hci_dev *hdev);
 void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
                       bool persistent);
 void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,
index bab8958bf46e9141a60513c040f914c27b27028a..484c75f3332cea9803354a4d49e7fae62e6fe4e7 100644 (file)
@@ -1537,7 +1537,6 @@ int hci_dev_do_close(struct hci_dev *hdev)
        flush_work(&hdev->rx_work);
 
        if (hdev->discov_timeout > 0) {
-               cancel_delayed_work(&hdev->discov_off);
                hdev->discov_timeout = 0;
                hci_dev_clear_flag(hdev, HCI_DISCOVERABLE);
                hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE);
@@ -2096,17 +2095,6 @@ static void hci_error_reset(struct work_struct *work)
        hci_dev_do_open(hdev);
 }
 
-static void hci_discov_off(struct work_struct *work)
-{
-       struct hci_dev *hdev;
-
-       hdev = container_of(work, struct hci_dev, discov_off.work);
-
-       BT_DBG("%s", hdev->name);
-
-       mgmt_discoverable_timeout(hdev);
-}
-
 void hci_uuids_clear(struct hci_dev *hdev)
 {
        struct bt_uuid *uuid, *tmp;
@@ -2986,7 +2974,6 @@ struct hci_dev *hci_alloc_dev(void)
        INIT_WORK(&hdev->error_reset, hci_error_reset);
 
        INIT_DELAYED_WORK(&hdev->power_off, hci_power_off);
-       INIT_DELAYED_WORK(&hdev->discov_off, hci_discov_off);
 
        skb_queue_head_init(&hdev->rx_q);
        skb_queue_head_init(&hdev->cmd_q);
index 8f72218ed805f06a9ebf61037da54478f9a137c3..fe14fd121d367e55f0d4485c489123399efe46ae 100644 (file)
@@ -1923,6 +1923,30 @@ static void discov_update(struct work_struct *work)
        }
 }
 
+static void discov_off(struct work_struct *work)
+{
+       struct hci_dev *hdev = container_of(work, struct hci_dev,
+                                           discov_off.work);
+
+       BT_DBG("%s", hdev->name);
+
+       hci_dev_lock(hdev);
+
+       /* When discoverable timeout triggers, then just make sure
+        * the limited discoverable flag is cleared. Even in the case
+        * of a timeout triggered from general discoverable, it is
+        * safe to unconditionally clear the flag.
+        */
+       hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE);
+       hci_dev_clear_flag(hdev, HCI_DISCOVERABLE);
+       hdev->discov_timeout = 0;
+
+       hci_dev_unlock(hdev);
+
+       hci_req_sync(hdev, discoverable_update, 0, HCI_CMD_TIMEOUT, NULL);
+       mgmt_new_settings(hdev);
+}
+
 void hci_request_setup(struct hci_dev *hdev)
 {
        INIT_WORK(&hdev->discov_update, discov_update);
@@ -1930,6 +1954,7 @@ void hci_request_setup(struct hci_dev *hdev)
        INIT_WORK(&hdev->scan_update, scan_update_work);
        INIT_WORK(&hdev->connectable_update, connectable_update_work);
        INIT_WORK(&hdev->discoverable_update, discoverable_update_work);
+       INIT_DELAYED_WORK(&hdev->discov_off, discov_off);
        INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable_work);
        INIT_DELAYED_WORK(&hdev->le_scan_restart, le_scan_restart_work);
        INIT_DELAYED_WORK(&hdev->adv_instance_expire, adv_timeout_expire);
@@ -1944,6 +1969,7 @@ void hci_request_cancel_all(struct hci_dev *hdev)
        cancel_work_sync(&hdev->scan_update);
        cancel_work_sync(&hdev->connectable_update);
        cancel_work_sync(&hdev->discoverable_update);
+       cancel_delayed_work_sync(&hdev->discov_off);
        cancel_delayed_work_sync(&hdev->le_scan_disable);
        cancel_delayed_work_sync(&hdev->le_scan_restart);
 
index 8846cb3b0aaab580d57258dc2910aed655d91ccc..29b3bb70ae9f39f48d6cc75bfcb88d6f2c695b6e 100644 (file)
@@ -1401,8 +1401,8 @@ static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data,
 
                if (cp->val && hdev->discov_timeout > 0) {
                        int to = msecs_to_jiffies(hdev->discov_timeout * 1000);
-                       queue_delayed_work(hdev->workqueue, &hdev->discov_off,
-                                          to);
+                       queue_delayed_work(hdev->req_workqueue,
+                                          &hdev->discov_off, to);
                }
 
                err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev);
@@ -6848,43 +6848,6 @@ void mgmt_set_powered_failed(struct hci_dev *hdev, int err)
        mgmt_pending_remove(cmd);
 }
 
-void mgmt_discoverable_timeout(struct hci_dev *hdev)
-{
-       struct hci_request req;
-
-       hci_dev_lock(hdev);
-
-       /* When discoverable timeout triggers, then just make sure
-        * the limited discoverable flag is cleared. Even in the case
-        * of a timeout triggered from general discoverable, it is
-        * safe to unconditionally clear the flag.
-        */
-       hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE);
-       hci_dev_clear_flag(hdev, HCI_DISCOVERABLE);
-
-       hci_req_init(&req, hdev);
-       if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) {
-               u8 scan = SCAN_PAGE;
-               hci_req_add(&req, HCI_OP_WRITE_SCAN_ENABLE,
-                           sizeof(scan), &scan);
-       }
-       __hci_req_update_class(&req);
-
-       /* Advertising instances don't use the global discoverable setting, so
-        * only update AD if advertising was enabled using Set Advertising.
-        */
-       if (hci_dev_test_flag(hdev, HCI_ADVERTISING))
-               __hci_req_update_adv_data(&req, HCI_ADV_CURRENT);
-
-       hci_req_run(&req, NULL);
-
-       hdev->discov_timeout = 0;
-
-       new_settings(hdev, NULL);
-
-       hci_dev_unlock(hdev);
-}
-
 void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
                       bool persistent)
 {