aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@googlemail.com>2012-04-22 08:39:58 -0400
committerGustavo Padovan <gustavo@padovan.org>2012-05-09 00:40:40 -0400
commitb1b813d4777f4843af2acce9a1b62d486e1d3ffc (patch)
tree46fdd34d9e2fdca1c70b0efe4f05f8cd54460741 /net/bluetooth
parent9be0dab793f52615274c357fce542b3cbf78f6d7 (diff)
Bluetooth: Move device initialization to hci_alloc_dev()
We currently initialize locks, lists, works, etc. in hci_register_dev() (hci_alloc_dev() was added later) which is bogus because an hdev is in an invalid state if it is not registered. This patch moves all memory initialization to hci_alloc_dev(). Device registering and registration of sub-modules is still left in hci_register_dev() as it belongs there. The benefit is (despite cleaning up the code-base) we can now always be sure that an hdev is a valid object and can be locked and worked on even though it may not be registered. This patch also reorders the initialization to be easier to understand. First the memory is initialized, then all generic structures and as last step the sub-init functions are called. This guarantees that all dependencies are initialized in the right order and makes it also easier to find a specific line. We previously initialized it in the same order as the "struct hci_dev" is declared which seems pretty random. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth')
-rw-r--r--net/bluetooth/hci_core.c115
1 files changed, 52 insertions, 63 deletions
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index d3fb986d6b27..a362f01bf081 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1713,13 +1713,63 @@ int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window,
1713struct hci_dev *hci_alloc_dev(void) 1713struct hci_dev *hci_alloc_dev(void)
1714{ 1714{
1715 struct hci_dev *hdev; 1715 struct hci_dev *hdev;
1716 int i;
1716 1717
1717 hdev = kzalloc(sizeof(struct hci_dev), GFP_KERNEL); 1718 hdev = kzalloc(sizeof(struct hci_dev), GFP_KERNEL);
1718 if (!hdev) 1719 if (!hdev)
1719 return NULL; 1720 return NULL;
1720 1721
1721 hci_init_sysfs(hdev); 1722 hdev->flags = 0;
1723 hdev->dev_flags = 0;
1724 hdev->pkt_type = (HCI_DM1 | HCI_DH1 | HCI_HV1);
1725 hdev->esco_type = (ESCO_HV1);
1726 hdev->link_mode = (HCI_LM_ACCEPT);
1727 hdev->io_capability = 0x03; /* No Input No Output */
1728
1729 hdev->idle_timeout = 0;
1730 hdev->sniff_max_interval = 800;
1731 hdev->sniff_min_interval = 80;
1732
1733 mutex_init(&hdev->lock);
1734 mutex_init(&hdev->req_lock);
1735
1736 INIT_LIST_HEAD(&hdev->mgmt_pending);
1737 INIT_LIST_HEAD(&hdev->blacklist);
1738 INIT_LIST_HEAD(&hdev->uuids);
1739 INIT_LIST_HEAD(&hdev->link_keys);
1740 INIT_LIST_HEAD(&hdev->long_term_keys);
1741 INIT_LIST_HEAD(&hdev->remote_oob_data);
1742 INIT_LIST_HEAD(&hdev->adv_entries);
1743
1744 INIT_WORK(&hdev->rx_work, hci_rx_work);
1745 INIT_WORK(&hdev->cmd_work, hci_cmd_work);
1746 INIT_WORK(&hdev->tx_work, hci_tx_work);
1747 INIT_WORK(&hdev->power_on, hci_power_on);
1748 INIT_WORK(&hdev->le_scan, le_scan_work);
1749
1750 INIT_DELAYED_WORK(&hdev->adv_work, hci_clear_adv_cache);
1751 INIT_DELAYED_WORK(&hdev->power_off, hci_power_off);
1752 INIT_DELAYED_WORK(&hdev->discov_off, hci_discov_off);
1753 INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable_work);
1754
1722 skb_queue_head_init(&hdev->driver_init); 1755 skb_queue_head_init(&hdev->driver_init);
1756 skb_queue_head_init(&hdev->rx_q);
1757 skb_queue_head_init(&hdev->cmd_q);
1758 skb_queue_head_init(&hdev->raw_q);
1759
1760 init_waitqueue_head(&hdev->req_wait_q);
1761
1762 setup_timer(&hdev->cmd_timer, hci_cmd_timer, (unsigned long) hdev);
1763
1764 memset(&hdev->stat, 0, sizeof(struct hci_dev_stats));
1765 atomic_set(&hdev->promisc, 0);
1766
1767 for (i = 0; i < NUM_REASSEMBLY; i++)
1768 hdev->reassembly[i] = NULL;
1769
1770 hci_init_sysfs(hdev);
1771 discovery_init(hdev);
1772 hci_conn_hash_init(hdev);
1723 1773
1724 return hdev; 1774 return hdev;
1725} 1775}
@@ -1739,7 +1789,7 @@ EXPORT_SYMBOL(hci_free_dev);
1739int hci_register_dev(struct hci_dev *hdev) 1789int hci_register_dev(struct hci_dev *hdev)
1740{ 1790{
1741 struct list_head *head, *p; 1791 struct list_head *head, *p;
1742 int i, id, error; 1792 int id, error;
1743 1793
1744 if (!hdev->open || !hdev->close) 1794 if (!hdev->open || !hdev->close)
1745 return -EINVAL; 1795 return -EINVAL;
@@ -1769,67 +1819,6 @@ int hci_register_dev(struct hci_dev *hdev)
1769 1819
1770 list_add(&hdev->list, head); 1820 list_add(&hdev->list, head);
1771 1821
1772 mutex_init(&hdev->lock);
1773
1774 hdev->flags = 0;
1775 hdev->dev_flags = 0;
1776 hdev->pkt_type = (HCI_DM1 | HCI_DH1 | HCI_HV1);
1777 hdev->esco_type = (ESCO_HV1);
1778 hdev->link_mode = (HCI_LM_ACCEPT);
1779 hdev->io_capability = 0x03; /* No Input No Output */
1780
1781 hdev->idle_timeout = 0;
1782 hdev->sniff_max_interval = 800;
1783 hdev->sniff_min_interval = 80;
1784
1785 INIT_WORK(&hdev->rx_work, hci_rx_work);
1786 INIT_WORK(&hdev->cmd_work, hci_cmd_work);
1787 INIT_WORK(&hdev->tx_work, hci_tx_work);
1788
1789
1790 skb_queue_head_init(&hdev->rx_q);
1791 skb_queue_head_init(&hdev->cmd_q);
1792 skb_queue_head_init(&hdev->raw_q);
1793
1794 setup_timer(&hdev->cmd_timer, hci_cmd_timer, (unsigned long) hdev);
1795
1796 for (i = 0; i < NUM_REASSEMBLY; i++)
1797 hdev->reassembly[i] = NULL;
1798
1799 init_waitqueue_head(&hdev->req_wait_q);
1800 mutex_init(&hdev->req_lock);
1801
1802 discovery_init(hdev);
1803
1804 hci_conn_hash_init(hdev);
1805
1806 INIT_LIST_HEAD(&hdev->mgmt_pending);
1807
1808 INIT_LIST_HEAD(&hdev->blacklist);
1809
1810 INIT_LIST_HEAD(&hdev->uuids);
1811
1812 INIT_LIST_HEAD(&hdev->link_keys);
1813 INIT_LIST_HEAD(&hdev->long_term_keys);
1814
1815 INIT_LIST_HEAD(&hdev->remote_oob_data);
1816
1817 INIT_LIST_HEAD(&hdev->adv_entries);
1818
1819 INIT_DELAYED_WORK(&hdev->adv_work, hci_clear_adv_cache);
1820 INIT_WORK(&hdev->power_on, hci_power_on);
1821 INIT_DELAYED_WORK(&hdev->power_off, hci_power_off);
1822
1823 INIT_DELAYED_WORK(&hdev->discov_off, hci_discov_off);
1824
1825 memset(&hdev->stat, 0, sizeof(struct hci_dev_stats));
1826
1827 atomic_set(&hdev->promisc, 0);
1828
1829 INIT_WORK(&hdev->le_scan, le_scan_work);
1830
1831 INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable_work);
1832
1833 write_unlock(&hci_dev_list_lock); 1822 write_unlock(&hci_dev_list_lock);
1834 1823
1835 hdev->workqueue = alloc_workqueue(hdev->name, WQ_HIGHPRI | WQ_UNBOUND | 1824 hdev->workqueue = alloc_workqueue(hdev->name, WQ_HIGHPRI | WQ_UNBOUND |