aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2013-04-29 12:35:43 -0400
committerGustavo Padovan <gustavo.padovan@collabora.co.uk>2013-06-22 19:23:49 -0400
commit5ee9891dd8a63df1bf2ccd437872ad30a5850449 (patch)
tree7ef219c2f84595edfbf6b39eef69a0797a05732d /net/bluetooth
parentaf1c01349ecc2b8ab2c329e4dbd46e9018469bd1 (diff)
Bluetooth: Simplify hci_conn_hold/drop logic for L2CAP
The L2CAP code has been incrementing the hci_conn reference for each l2cap_chan instance in the l2cap_conn list. Likewise, the reference is dropped each time an l2cap_chan is removed from the list. The reference counting policy with respect to removal has been clear and explicit in the l2cap_chan_del function, however for addition the function calling 2cap_chan_add has always had to do a separate hci_conn_hold call. What made the counting even more hard to follow is that the hci_connect() procedure increments the reference and the L2CAP layer making this call took advantage of it to use it as its own reference. This patch aims to clarify things by having the call to hci_conn_hold inside __l2cap_chan_add, thereby removing the need to do it in the functions calling __l2cap_chan_add. The reference count for hci_connect is still kept as it's necessary for users such as mgmt_pair_device, however for the L2CAP layer it means that an extra call to hci_conn_drop must be performed once l2cap_chan_add has been done. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Acked-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Diffstat (limited to 'net/bluetooth')
-rw-r--r--net/bluetooth/l2cap_core.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 55c6836796f7..d7b501ba2716 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -545,6 +545,8 @@ void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
545 545
546 l2cap_chan_hold(chan); 546 l2cap_chan_hold(chan);
547 547
548 hci_conn_hold(conn->hcon);
549
548 list_add(&chan->list, &conn->chan_l); 550 list_add(&chan->list, &conn->chan_l);
549} 551}
550 552
@@ -1361,7 +1363,6 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
1361 1363
1362 chan->dcid = L2CAP_CID_ATT; 1364 chan->dcid = L2CAP_CID_ATT;
1363 1365
1364 hci_conn_hold(conn->hcon);
1365 conn->hcon->disc_timeout = HCI_DISCONN_TIMEOUT; 1366 conn->hcon->disc_timeout = HCI_DISCONN_TIMEOUT;
1366 1367
1367 bacpy(&bt_sk(chan->sk)->src, conn->src); 1368 bacpy(&bt_sk(chan->sk)->src, conn->src);
@@ -1827,6 +1828,9 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
1827 l2cap_chan_add(conn, chan); 1828 l2cap_chan_add(conn, chan);
1828 l2cap_chan_lock(chan); 1829 l2cap_chan_lock(chan);
1829 1830
1831 /* l2cap_chan_add takes its own ref so we can drop this one */
1832 hci_conn_drop(hcon);
1833
1830 l2cap_state_change(chan, BT_CONNECT); 1834 l2cap_state_change(chan, BT_CONNECT);
1831 __set_chan_timer(chan, sk->sk_sndtimeo); 1835 __set_chan_timer(chan, sk->sk_sndtimeo);
1832 1836
@@ -3748,8 +3752,6 @@ static struct l2cap_chan *l2cap_connect(struct l2cap_conn *conn,
3748 3752
3749 sk = chan->sk; 3753 sk = chan->sk;
3750 3754
3751 hci_conn_hold(conn->hcon);
3752
3753 bacpy(&bt_sk(sk)->src, conn->src); 3755 bacpy(&bt_sk(sk)->src, conn->src);
3754 bacpy(&bt_sk(sk)->dst, conn->dst); 3756 bacpy(&bt_sk(sk)->dst, conn->dst);
3755 chan->psm = psm; 3757 chan->psm = psm;