aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlisses Furquim <ulisses@profusion.mobi>2012-04-18 11:13:04 -0400
committerGustavo Padovan <gustavo@padovan.org>2012-05-09 00:40:38 -0400
commitfc50744c1e518adfb4ff2eda156f941e20aea36d (patch)
treea03c61a9c59c57dcd3bda1b572dc913c8f4798d8
parent519e42b38ee47005aaa2243789cda54161e62dc8 (diff)
Bluetooth: Fix registering hci with duplicate name
When adding HCI devices hci_register_dev assigns the same name hci1 for subsequently added AMP devices. ... [ 6958.381886] sysfs: cannot create duplicate filename '/devices/virtual/bluetooth/hci1 ... We assume id starts with the number we'll try to add the new device and keep iterating until we find the proper place. The only difference is we start with 0 for BR/EDR device and 1 for AMP devices (thus AMP devices will never receive register as index 0). Then every hdev->id in the _ordered_ list <= to the id we want we increment id and move the variable head. In the end we'll have id as the first available one and head is where you need to add hdev after to keep the list ordered. Reported-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com> Signed-off-by: Ulisses Furquim <ulisses@profusion.mobi> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r--net/bluetooth/hci_core.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 544c7e3a40d2..22581823e610 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1738,24 +1738,28 @@ int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window,
1738/* Register HCI device */ 1738/* Register HCI device */
1739int hci_register_dev(struct hci_dev *hdev) 1739int hci_register_dev(struct hci_dev *hdev)
1740{ 1740{
1741 struct list_head *head = &hci_dev_list, *p; 1741 struct list_head *head, *p;
1742 int i, id, error; 1742 int i, id, error;
1743 1743
1744 if (!hdev->open || !hdev->close) 1744 if (!hdev->open || !hdev->close)
1745 return -EINVAL; 1745 return -EINVAL;
1746 1746
1747 write_lock(&hci_dev_list_lock);
1748
1747 /* Do not allow HCI_AMP devices to register at index 0, 1749 /* Do not allow HCI_AMP devices to register at index 0,
1748 * so the index can be used as the AMP controller ID. 1750 * so the index can be used as the AMP controller ID.
1749 */ 1751 */
1750 id = (hdev->dev_type == HCI_BREDR) ? 0 : 1; 1752 id = (hdev->dev_type == HCI_BREDR) ? 0 : 1;
1751 1753 head = &hci_dev_list;
1752 write_lock(&hci_dev_list_lock);
1753 1754
1754 /* Find first available device id */ 1755 /* Find first available device id */
1755 list_for_each(p, &hci_dev_list) { 1756 list_for_each(p, &hci_dev_list) {
1756 if (list_entry(p, struct hci_dev, list)->id != id) 1757 int nid = list_entry(p, struct hci_dev, list)->id;
1758 if (nid > id)
1757 break; 1759 break;
1758 head = p; id++; 1760 if (nid == id)
1761 id++;
1762 head = p;
1759 } 1763 }
1760 1764
1761 sprintf(hdev->name, "hci%d", id); 1765 sprintf(hdev->name, "hci%d", id);
@@ -1763,7 +1767,7 @@ int hci_register_dev(struct hci_dev *hdev)
1763 1767
1764 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); 1768 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
1765 1769
1766 list_add_tail(&hdev->list, head); 1770 list_add(&hdev->list, head);
1767 1771
1768 mutex_init(&hdev->lock); 1772 mutex_init(&hdev->lock);
1769 1773