aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2012-02-23 02:52:28 -0500
committerJohan Hedberg <johan.hedberg@intel.com>2012-02-23 06:07:02 -0500
commit60fc5fb66efa0bcbe028637206ed59df8cd4ac19 (patch)
treea44a49c3003eb7377e1428c276e26895cb029c41 /net
parentb3fb611ec7b76048cb14600e9a5a9b57e5d913da (diff)
Bluetooth: mgmt: Fix count parameter in get_connections reply
This patch fixes the count parameter in the Get Connections reply message. We cannot know the right number until iterating through all connections so set the parameter value only after the loop. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Acked-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/mgmt.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 42d665bdc01..7fdba8fb980 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1725,8 +1725,8 @@ static int get_connections(struct sock *sk, u16 index)
1725 struct hci_dev *hdev; 1725 struct hci_dev *hdev;
1726 struct hci_conn *c; 1726 struct hci_conn *c;
1727 size_t rp_len; 1727 size_t rp_len;
1728 u16 count; 1728 int err;
1729 int i, err; 1729 u16 i;
1730 1730
1731 BT_DBG(""); 1731 BT_DBG("");
1732 1732
@@ -1743,21 +1743,19 @@ static int get_connections(struct sock *sk, u16 index)
1743 goto unlock; 1743 goto unlock;
1744 } 1744 }
1745 1745
1746 count = 0; 1746 i = 0;
1747 list_for_each_entry(c, &hdev->conn_hash.list, list) { 1747 list_for_each_entry(c, &hdev->conn_hash.list, list) {
1748 if (test_bit(HCI_CONN_MGMT_CONNECTED, &c->flags)) 1748 if (test_bit(HCI_CONN_MGMT_CONNECTED, &c->flags))
1749 count++; 1749 i++;
1750 } 1750 }
1751 1751
1752 rp_len = sizeof(*rp) + (count * sizeof(struct mgmt_addr_info)); 1752 rp_len = sizeof(*rp) + (i * sizeof(struct mgmt_addr_info));
1753 rp = kmalloc(rp_len, GFP_ATOMIC); 1753 rp = kmalloc(rp_len, GFP_ATOMIC);
1754 if (!rp) { 1754 if (!rp) {
1755 err = -ENOMEM; 1755 err = -ENOMEM;
1756 goto unlock; 1756 goto unlock;
1757 } 1757 }
1758 1758
1759 put_unaligned_le16(count, &rp->conn_count);
1760
1761 i = 0; 1759 i = 0;
1762 list_for_each_entry(c, &hdev->conn_hash.list, list) { 1760 list_for_each_entry(c, &hdev->conn_hash.list, list) {
1763 if (!test_bit(HCI_CONN_MGMT_CONNECTED, &c->flags)) 1761 if (!test_bit(HCI_CONN_MGMT_CONNECTED, &c->flags))
@@ -1769,6 +1767,8 @@ static int get_connections(struct sock *sk, u16 index)
1769 i++; 1767 i++;
1770 } 1768 }
1771 1769
1770 put_unaligned_le16(i, &rp->conn_count);
1771
1772 /* Recalculate length in case of filtered SCO connections, etc */ 1772 /* Recalculate length in case of filtered SCO connections, etc */
1773 rp_len = sizeof(*rp) + (i * sizeof(struct mgmt_addr_info)); 1773 rp_len = sizeof(*rp) + (i * sizeof(struct mgmt_addr_info));
1774 1774