aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2011-11-07 15:16:04 -0500
committerGustavo F. Padovan <padovan@profusion.mobi>2011-11-08 09:54:10 -0500
commit3243553fdc108a0ef49b9e25bdea9c87b341413e (patch)
treeb0ef367f37653b6fdefa3b028fdc0f2e685e5b2e
parent2d7cee5836d6d466829b255b1290c9386d4e884f (diff)
Bluetooth: Convert power off mechanism to use delayed_work
The power off code doesn't need to use its own custom timer since the delayed_work API provides the exact same functionality. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
-rw-r--r--include/net/bluetooth/hci_core.h3
-rw-r--r--net/bluetooth/hci_core.c39
-rw-r--r--net/bluetooth/mgmt.c8
3 files changed, 19 insertions, 31 deletions
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index c233bceb3ccc..bca53aa754e3 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -193,8 +193,7 @@ struct hci_dev {
193 struct workqueue_struct *workqueue; 193 struct workqueue_struct *workqueue;
194 194
195 struct work_struct power_on; 195 struct work_struct power_on;
196 struct work_struct power_off; 196 struct delayed_work power_off;
197 struct timer_list off_timer;
198 197
199 __u16 discov_timeout; 198 __u16 discov_timeout;
200 struct delayed_work discov_off; 199 struct delayed_work discov_off;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 2da3f907e9b7..e4ddf36d1701 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -600,6 +600,9 @@ static int hci_dev_do_close(struct hci_dev *hdev)
600 hdev->discov_timeout = 0; 600 hdev->discov_timeout = 0;
601 } 601 }
602 602
603 if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->flags))
604 cancel_delayed_work_sync(&hdev->power_off);
605
603 hci_dev_lock_bh(hdev); 606 hci_dev_lock_bh(hdev);
604 inquiry_cache_flush(hdev); 607 inquiry_cache_flush(hdev);
605 hci_conn_hash_flush(hdev); 608 hci_conn_hash_flush(hdev);
@@ -819,7 +822,8 @@ int hci_get_dev_list(void __user *arg)
819 822
820 read_lock_bh(&hci_dev_list_lock); 823 read_lock_bh(&hci_dev_list_lock);
821 list_for_each_entry(hdev, &hci_dev_list, list) { 824 list_for_each_entry(hdev, &hci_dev_list, list) {
822 hci_del_off_timer(hdev); 825 if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->flags))
826 cancel_delayed_work_sync(&hdev->power_off);
823 827
824 if (!test_bit(HCI_MGMT, &hdev->flags)) 828 if (!test_bit(HCI_MGMT, &hdev->flags))
825 set_bit(HCI_PAIRABLE, &hdev->flags); 829 set_bit(HCI_PAIRABLE, &hdev->flags);
@@ -854,7 +858,8 @@ int hci_get_dev_info(void __user *arg)
854 if (!hdev) 858 if (!hdev)
855 return -ENODEV; 859 return -ENODEV;
856 860
857 hci_del_off_timer(hdev); 861 if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->flags))
862 cancel_delayed_work_sync(&hdev->power_off);
858 863
859 if (!test_bit(HCI_MGMT, &hdev->flags)) 864 if (!test_bit(HCI_MGMT, &hdev->flags))
860 set_bit(HCI_PAIRABLE, &hdev->flags); 865 set_bit(HCI_PAIRABLE, &hdev->flags);
@@ -938,8 +943,8 @@ static void hci_power_on(struct work_struct *work)
938 return; 943 return;
939 944
940 if (test_bit(HCI_AUTO_OFF, &hdev->flags)) 945 if (test_bit(HCI_AUTO_OFF, &hdev->flags))
941 mod_timer(&hdev->off_timer, 946 queue_delayed_work(hdev->workqueue, &hdev->power_off,
942 jiffies + msecs_to_jiffies(AUTO_OFF_TIMEOUT)); 947 msecs_to_jiffies(AUTO_OFF_TIMEOUT));
943 948
944 if (test_and_clear_bit(HCI_SETUP, &hdev->flags)) 949 if (test_and_clear_bit(HCI_SETUP, &hdev->flags))
945 mgmt_index_added(hdev->id); 950 mgmt_index_added(hdev->id);
@@ -947,30 +952,14 @@ static void hci_power_on(struct work_struct *work)
947 952
948static void hci_power_off(struct work_struct *work) 953static void hci_power_off(struct work_struct *work)
949{ 954{
950 struct hci_dev *hdev = container_of(work, struct hci_dev, power_off); 955 struct hci_dev *hdev = container_of(work, struct hci_dev,
951 956 power_off.work);
952 BT_DBG("%s", hdev->name);
953
954 hci_dev_close(hdev->id);
955}
956
957static void hci_auto_off(unsigned long data)
958{
959 struct hci_dev *hdev = (struct hci_dev *) data;
960 957
961 BT_DBG("%s", hdev->name); 958 BT_DBG("%s", hdev->name);
962 959
963 clear_bit(HCI_AUTO_OFF, &hdev->flags); 960 clear_bit(HCI_AUTO_OFF, &hdev->flags);
964 961
965 queue_work(hdev->workqueue, &hdev->power_off); 962 hci_dev_close(hdev->id);
966}
967
968void hci_del_off_timer(struct hci_dev *hdev)
969{
970 BT_DBG("%s", hdev->name);
971
972 clear_bit(HCI_AUTO_OFF, &hdev->flags);
973 del_timer(&hdev->off_timer);
974} 963}
975 964
976static void hci_discov_off(struct work_struct *work) 965static void hci_discov_off(struct work_struct *work)
@@ -1505,8 +1494,7 @@ int hci_register_dev(struct hci_dev *hdev)
1505 (unsigned long) hdev); 1494 (unsigned long) hdev);
1506 1495
1507 INIT_WORK(&hdev->power_on, hci_power_on); 1496 INIT_WORK(&hdev->power_on, hci_power_on);
1508 INIT_WORK(&hdev->power_off, hci_power_off); 1497 INIT_DELAYED_WORK(&hdev->power_off, hci_power_off);
1509 setup_timer(&hdev->off_timer, hci_auto_off, (unsigned long) hdev);
1510 1498
1511 INIT_DELAYED_WORK(&hdev->discov_off, hci_discov_off); 1499 INIT_DELAYED_WORK(&hdev->discov_off, hci_discov_off);
1512 1500
@@ -1583,7 +1571,6 @@ void hci_unregister_dev(struct hci_dev *hdev)
1583 1571
1584 hci_del_sysfs(hdev); 1572 hci_del_sysfs(hdev);
1585 1573
1586 hci_del_off_timer(hdev);
1587 del_timer(&hdev->adv_timer); 1574 del_timer(&hdev->adv_timer);
1588 1575
1589 destroy_workqueue(hdev->workqueue); 1576 destroy_workqueue(hdev->workqueue);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 0cb023e0edb4..6f9e3cd0d1fd 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -150,7 +150,8 @@ static int read_index_list(struct sock *sk)
150 150
151 i = 0; 151 i = 0;
152 list_for_each_entry(d, &hci_dev_list, list) { 152 list_for_each_entry(d, &hci_dev_list, list) {
153 hci_del_off_timer(d); 153 if (test_and_clear_bit(HCI_AUTO_OFF, &d->flags))
154 cancel_delayed_work_sync(&d->power_off);
154 155
155 if (test_bit(HCI_SETUP, &d->flags)) 156 if (test_bit(HCI_SETUP, &d->flags))
156 continue; 157 continue;
@@ -180,7 +181,8 @@ static int read_controller_info(struct sock *sk, u16 index)
180 if (!hdev) 181 if (!hdev)
181 return cmd_status(sk, index, MGMT_OP_READ_INFO, ENODEV); 182 return cmd_status(sk, index, MGMT_OP_READ_INFO, ENODEV);
182 183
183 hci_del_off_timer(hdev); 184 if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->flags))
185 cancel_delayed_work_sync(&hdev->power_off);
184 186
185 hci_dev_lock_bh(hdev); 187 hci_dev_lock_bh(hdev);
186 188
@@ -337,7 +339,7 @@ static int set_powered(struct sock *sk, u16 index, unsigned char *data, u16 len)
337 if (cp->val) 339 if (cp->val)
338 queue_work(hdev->workqueue, &hdev->power_on); 340 queue_work(hdev->workqueue, &hdev->power_on);
339 else 341 else
340 queue_work(hdev->workqueue, &hdev->power_off); 342 queue_work(hdev->workqueue, &hdev->power_off.work);
341 343
342 err = 0; 344 err = 0;
343 345