Commit 76a68ba0 authored by David Herrmann's avatar David Herrmann Committed by Gustavo Padovan

Bluetooth: rename hci_conn_put to hci_conn_drop

We use _get() and _put() for device ref-counting in the kernel. However,
hci_conn_put() is _not_ used for ref-counting, hence, rename it to
hci_conn_drop() so we can later fix ref-counting and introduce
hci_conn_put().

hci_conn_hold() and hci_conn_put() are currently used to manage how long a
connection should be held alive. When the last user drops the connection,
we spawn a delayed work that performs the disconnect. Obviously, this has
nothing to do with ref-counting for the _object_ but rather for the
keep-alive of the connection.

But we really _need_ proper ref-counting for the _object_ to allow
connection-users like rfcomm-tty, HIDP or others.
Signed-off-by: default avatarDavid Herrmann <dh.herrmann@gmail.com>
Acked-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Signed-off-by: default avatarGustavo Padovan <gustavo.padovan@collabora.co.uk>
parent 9f8f962c
...@@ -612,7 +612,7 @@ static inline void hci_conn_hold(struct hci_conn *conn) ...@@ -612,7 +612,7 @@ static inline void hci_conn_hold(struct hci_conn *conn)
cancel_delayed_work(&conn->disc_work); cancel_delayed_work(&conn->disc_work);
} }
static inline void hci_conn_put(struct hci_conn *conn) static inline void hci_conn_drop(struct hci_conn *conn)
{ {
BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt)); BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
......
...@@ -433,7 +433,7 @@ int hci_conn_del(struct hci_conn *conn) ...@@ -433,7 +433,7 @@ int hci_conn_del(struct hci_conn *conn)
struct hci_conn *acl = conn->link; struct hci_conn *acl = conn->link;
if (acl) { if (acl) {
acl->link = NULL; acl->link = NULL;
hci_conn_put(acl); hci_conn_drop(acl);
} }
} }
...@@ -565,7 +565,7 @@ static struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, ...@@ -565,7 +565,7 @@ static struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type,
if (!sco) { if (!sco) {
sco = hci_conn_add(hdev, type, dst); sco = hci_conn_add(hdev, type, dst);
if (!sco) { if (!sco) {
hci_conn_put(acl); hci_conn_drop(acl);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
} }
...@@ -980,7 +980,7 @@ void hci_chan_del(struct hci_chan *chan) ...@@ -980,7 +980,7 @@ void hci_chan_del(struct hci_chan *chan)
synchronize_rcu(); synchronize_rcu();
hci_conn_put(conn); hci_conn_drop(conn);
skb_queue_purge(&chan->data_q); skb_queue_purge(&chan->data_q);
kfree(chan); kfree(chan);
......
...@@ -1190,7 +1190,7 @@ static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status) ...@@ -1190,7 +1190,7 @@ static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status)
if (conn) { if (conn) {
if (conn->state == BT_CONFIG) { if (conn->state == BT_CONFIG) {
hci_proto_connect_cfm(conn, status); hci_proto_connect_cfm(conn, status);
hci_conn_put(conn); hci_conn_drop(conn);
} }
} }
...@@ -1217,7 +1217,7 @@ static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status) ...@@ -1217,7 +1217,7 @@ static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status)
if (conn) { if (conn) {
if (conn->state == BT_CONFIG) { if (conn->state == BT_CONFIG) {
hci_proto_connect_cfm(conn, status); hci_proto_connect_cfm(conn, status);
hci_conn_put(conn); hci_conn_drop(conn);
} }
} }
...@@ -1379,7 +1379,7 @@ static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status) ...@@ -1379,7 +1379,7 @@ static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status)
if (conn) { if (conn) {
if (conn->state == BT_CONFIG) { if (conn->state == BT_CONFIG) {
hci_proto_connect_cfm(conn, status); hci_proto_connect_cfm(conn, status);
hci_conn_put(conn); hci_conn_drop(conn);
} }
} }
...@@ -1406,7 +1406,7 @@ static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status) ...@@ -1406,7 +1406,7 @@ static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status)
if (conn) { if (conn) {
if (conn->state == BT_CONFIG) { if (conn->state == BT_CONFIG) {
hci_proto_connect_cfm(conn, status); hci_proto_connect_cfm(conn, status);
hci_conn_put(conn); hci_conn_drop(conn);
} }
} }
...@@ -1860,7 +1860,7 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -1860,7 +1860,7 @@ static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
} else { } else {
conn->state = BT_CONNECT2; conn->state = BT_CONNECT2;
hci_proto_connect_cfm(conn, 0); hci_proto_connect_cfm(conn, 0);
hci_conn_put(conn); hci_conn_drop(conn);
} }
} else { } else {
/* Connection rejected */ /* Connection rejected */
...@@ -1967,14 +1967,14 @@ static void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -1967,14 +1967,14 @@ static void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
} else { } else {
conn->state = BT_CONNECTED; conn->state = BT_CONNECTED;
hci_proto_connect_cfm(conn, ev->status); hci_proto_connect_cfm(conn, ev->status);
hci_conn_put(conn); hci_conn_drop(conn);
} }
} else { } else {
hci_auth_cfm(conn, ev->status); hci_auth_cfm(conn, ev->status);
hci_conn_hold(conn); hci_conn_hold(conn);
conn->disc_timeout = HCI_DISCONN_TIMEOUT; conn->disc_timeout = HCI_DISCONN_TIMEOUT;
hci_conn_put(conn); hci_conn_drop(conn);
} }
if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) { if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) {
...@@ -2058,7 +2058,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -2058,7 +2058,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
if (ev->status && conn->state == BT_CONNECTED) { if (ev->status && conn->state == BT_CONNECTED) {
hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
hci_conn_put(conn); hci_conn_drop(conn);
goto unlock; goto unlock;
} }
...@@ -2067,7 +2067,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -2067,7 +2067,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
conn->state = BT_CONNECTED; conn->state = BT_CONNECTED;
hci_proto_connect_cfm(conn, ev->status); hci_proto_connect_cfm(conn, ev->status);
hci_conn_put(conn); hci_conn_drop(conn);
} else } else
hci_encrypt_cfm(conn, ev->status, ev->encrypt); hci_encrypt_cfm(conn, ev->status, ev->encrypt);
} }
...@@ -2142,7 +2142,7 @@ static void hci_remote_features_evt(struct hci_dev *hdev, ...@@ -2142,7 +2142,7 @@ static void hci_remote_features_evt(struct hci_dev *hdev,
if (!hci_outgoing_auth_needed(hdev, conn)) { if (!hci_outgoing_auth_needed(hdev, conn)) {
conn->state = BT_CONNECTED; conn->state = BT_CONNECTED;
hci_proto_connect_cfm(conn, ev->status); hci_proto_connect_cfm(conn, ev->status);
hci_conn_put(conn); hci_conn_drop(conn);
} }
unlock: unlock:
...@@ -2682,7 +2682,7 @@ static void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -2682,7 +2682,7 @@ static void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
if (conn->state == BT_CONNECTED) { if (conn->state == BT_CONNECTED) {
hci_conn_hold(conn); hci_conn_hold(conn);
conn->disc_timeout = HCI_PAIRING_TIMEOUT; conn->disc_timeout = HCI_PAIRING_TIMEOUT;
hci_conn_put(conn); hci_conn_drop(conn);
} }
if (!test_bit(HCI_PAIRABLE, &hdev->dev_flags)) if (!test_bit(HCI_PAIRABLE, &hdev->dev_flags))
...@@ -2785,7 +2785,7 @@ static void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -2785,7 +2785,7 @@ static void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
if (ev->key_type != HCI_LK_CHANGED_COMBINATION) if (ev->key_type != HCI_LK_CHANGED_COMBINATION)
conn->key_type = ev->key_type; conn->key_type = ev->key_type;
hci_conn_put(conn); hci_conn_drop(conn);
} }
if (test_bit(HCI_LINK_KEYS, &hdev->dev_flags)) if (test_bit(HCI_LINK_KEYS, &hdev->dev_flags))
...@@ -2954,7 +2954,7 @@ static void hci_remote_ext_features_evt(struct hci_dev *hdev, ...@@ -2954,7 +2954,7 @@ static void hci_remote_ext_features_evt(struct hci_dev *hdev,
if (!hci_outgoing_auth_needed(hdev, conn)) { if (!hci_outgoing_auth_needed(hdev, conn)) {
conn->state = BT_CONNECTED; conn->state = BT_CONNECTED;
hci_proto_connect_cfm(conn, ev->status); hci_proto_connect_cfm(conn, ev->status);
hci_conn_put(conn); hci_conn_drop(conn);
} }
unlock: unlock:
...@@ -3087,7 +3087,7 @@ static void hci_key_refresh_complete_evt(struct hci_dev *hdev, ...@@ -3087,7 +3087,7 @@ static void hci_key_refresh_complete_evt(struct hci_dev *hdev,
if (ev->status && conn->state == BT_CONNECTED) { if (ev->status && conn->state == BT_CONNECTED) {
hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
hci_conn_put(conn); hci_conn_drop(conn);
goto unlock; goto unlock;
} }
...@@ -3096,13 +3096,13 @@ static void hci_key_refresh_complete_evt(struct hci_dev *hdev, ...@@ -3096,13 +3096,13 @@ static void hci_key_refresh_complete_evt(struct hci_dev *hdev,
conn->state = BT_CONNECTED; conn->state = BT_CONNECTED;
hci_proto_connect_cfm(conn, ev->status); hci_proto_connect_cfm(conn, ev->status);
hci_conn_put(conn); hci_conn_drop(conn);
} else { } else {
hci_auth_cfm(conn, ev->status); hci_auth_cfm(conn, ev->status);
hci_conn_hold(conn); hci_conn_hold(conn);
conn->disc_timeout = HCI_DISCONN_TIMEOUT; conn->disc_timeout = HCI_DISCONN_TIMEOUT;
hci_conn_put(conn); hci_conn_drop(conn);
} }
unlock: unlock:
...@@ -3363,7 +3363,7 @@ static void hci_simple_pair_complete_evt(struct hci_dev *hdev, ...@@ -3363,7 +3363,7 @@ static void hci_simple_pair_complete_evt(struct hci_dev *hdev,
mgmt_auth_failed(hdev, &conn->dst, conn->type, conn->dst_type, mgmt_auth_failed(hdev, &conn->dst, conn->type, conn->dst_type,
ev->status); ev->status);
hci_conn_put(conn); hci_conn_drop(conn);
unlock: unlock:
hci_dev_unlock(hdev); hci_dev_unlock(hdev);
...@@ -3451,7 +3451,7 @@ static void hci_phy_link_complete_evt(struct hci_dev *hdev, ...@@ -3451,7 +3451,7 @@ static void hci_phy_link_complete_evt(struct hci_dev *hdev,
hci_conn_hold(hcon); hci_conn_hold(hcon);
hcon->disc_timeout = HCI_DISCONN_TIMEOUT; hcon->disc_timeout = HCI_DISCONN_TIMEOUT;
hci_conn_put(hcon); hci_conn_drop(hcon);
hci_conn_hold_device(hcon); hci_conn_hold_device(hcon);
hci_conn_add_sysfs(hcon); hci_conn_add_sysfs(hcon);
......
...@@ -571,7 +571,7 @@ void l2cap_chan_del(struct l2cap_chan *chan, int err) ...@@ -571,7 +571,7 @@ void l2cap_chan_del(struct l2cap_chan *chan, int err)
chan->conn = NULL; chan->conn = NULL;
if (chan->chan_type != L2CAP_CHAN_CONN_FIX_A2MP) if (chan->chan_type != L2CAP_CHAN_CONN_FIX_A2MP)
hci_conn_put(conn->hcon); hci_conn_drop(conn->hcon);
if (mgr && mgr->bredr_chan == chan) if (mgr && mgr->bredr_chan == chan)
mgr->bredr_chan = NULL; mgr->bredr_chan = NULL;
...@@ -1697,7 +1697,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, ...@@ -1697,7 +1697,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
conn = l2cap_conn_add(hcon, 0); conn = l2cap_conn_add(hcon, 0);
if (!conn) { if (!conn) {
hci_conn_put(hcon); hci_conn_drop(hcon);
err = -ENOMEM; err = -ENOMEM;
goto done; goto done;
} }
...@@ -1707,7 +1707,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, ...@@ -1707,7 +1707,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
if (!list_empty(&conn->chan_l)) { if (!list_empty(&conn->chan_l)) {
err = -EBUSY; err = -EBUSY;
hci_conn_put(hcon); hci_conn_drop(hcon);
} }
if (err) if (err)
......
...@@ -2131,7 +2131,7 @@ static void pairing_complete(struct pending_cmd *cmd, u8 status) ...@@ -2131,7 +2131,7 @@ static void pairing_complete(struct pending_cmd *cmd, u8 status)
conn->security_cfm_cb = NULL; conn->security_cfm_cb = NULL;
conn->disconn_cfm_cb = NULL; conn->disconn_cfm_cb = NULL;
hci_conn_put(conn); hci_conn_drop(conn);
mgmt_pending_remove(cmd); mgmt_pending_remove(cmd);
} }
...@@ -2222,7 +2222,7 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, ...@@ -2222,7 +2222,7 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
} }
if (conn->connect_cfm_cb) { if (conn->connect_cfm_cb) {
hci_conn_put(conn); hci_conn_drop(conn);
err = cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, err = cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE,
MGMT_STATUS_BUSY, &rp, sizeof(rp)); MGMT_STATUS_BUSY, &rp, sizeof(rp));
goto unlock; goto unlock;
...@@ -2231,7 +2231,7 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, ...@@ -2231,7 +2231,7 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
cmd = mgmt_pending_add(sk, MGMT_OP_PAIR_DEVICE, hdev, data, len); cmd = mgmt_pending_add(sk, MGMT_OP_PAIR_DEVICE, hdev, data, len);
if (!cmd) { if (!cmd) {
err = -ENOMEM; err = -ENOMEM;
hci_conn_put(conn); hci_conn_drop(conn);
goto unlock; goto unlock;
} }
......
...@@ -185,7 +185,7 @@ static int sco_connect(struct sock *sk) ...@@ -185,7 +185,7 @@ static int sco_connect(struct sock *sk)
conn = sco_conn_add(hcon); conn = sco_conn_add(hcon);
if (!conn) { if (!conn) {
hci_conn_put(hcon); hci_conn_drop(hcon);
err = -ENOMEM; err = -ENOMEM;
goto done; goto done;
} }
...@@ -353,7 +353,7 @@ static void __sco_sock_close(struct sock *sk) ...@@ -353,7 +353,7 @@ static void __sco_sock_close(struct sock *sk)
if (sco_pi(sk)->conn->hcon) { if (sco_pi(sk)->conn->hcon) {
sk->sk_state = BT_DISCONN; sk->sk_state = BT_DISCONN;
sco_sock_set_timer(sk, SCO_DISCONN_TIMEOUT); sco_sock_set_timer(sk, SCO_DISCONN_TIMEOUT);
hci_conn_put(sco_pi(sk)->conn->hcon); hci_conn_drop(sco_pi(sk)->conn->hcon);
sco_pi(sk)->conn->hcon = NULL; sco_pi(sk)->conn->hcon = NULL;
} else } else
sco_chan_del(sk, ECONNRESET); sco_chan_del(sk, ECONNRESET);
...@@ -882,7 +882,7 @@ static void sco_chan_del(struct sock *sk, int err) ...@@ -882,7 +882,7 @@ static void sco_chan_del(struct sock *sk, int err)
sco_conn_unlock(conn); sco_conn_unlock(conn);
if (conn->hcon) if (conn->hcon)
hci_conn_put(conn->hcon); hci_conn_drop(conn->hcon);
} }
sk->sk_state = BT_CLOSED; sk->sk_state = BT_CLOSED;
......
...@@ -522,7 +522,7 @@ void smp_chan_destroy(struct l2cap_conn *conn) ...@@ -522,7 +522,7 @@ void smp_chan_destroy(struct l2cap_conn *conn)
kfree(smp); kfree(smp);
conn->smp_chan = NULL; conn->smp_chan = NULL;
conn->hcon->smp_conn = NULL; conn->hcon->smp_conn = NULL;
hci_conn_put(conn->hcon); hci_conn_drop(conn->hcon);
} }
int smp_user_confirm_reply(struct hci_conn *hcon, u16 mgmt_op, __le32 passkey) int smp_user_confirm_reply(struct hci_conn *hcon, u16 mgmt_op, __le32 passkey)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment