aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2014-08-15 14:06:57 -0400
committerMarcel Holtmann <marcel@holtmann.org>2014-09-08 13:07:52 -0400
commit51bb8457ddfa74ede52bf8c02054dea831d59fff (patch)
tree668dd96aa65093142ca79ce55cdca68067fcc129
parent5477610fc187d4aae0f699d21dfb0e3f440f7de7 (diff)
Bluetooth: Improve *_get() functions to return the object type
It's natural to have *_get() functions that increment the reference count of an object to return the object type itself. This way it's simple to make a copy of the object pointer and increase the reference count in a single step. This patch updates two such get() functions, namely hci_conn_get() and l2cap_conn_get(), and updates the users to take advantage of the new API. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r--include/net/bluetooth/hci_core.h3
-rw-r--r--include/net/bluetooth/l2cap.h2
-rw-r--r--net/bluetooth/hidp/core.c10
-rw-r--r--net/bluetooth/l2cap_core.c6
4 files changed, 10 insertions, 11 deletions
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index b0ded1333865..aa75eee8ad7f 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -756,9 +756,10 @@ void hci_le_conn_failed(struct hci_conn *conn, u8 status);
756 * _get()/_drop() in it, but require the caller to have a valid ref (FIXME). 756 * _get()/_drop() in it, but require the caller to have a valid ref (FIXME).
757 */ 757 */
758 758
759static inline void hci_conn_get(struct hci_conn *conn) 759static inline struct hci_conn *hci_conn_get(struct hci_conn *conn)
760{ 760{
761 get_device(&conn->dev); 761 get_device(&conn->dev);
762 return conn;
762} 763}
763 764
764static inline void hci_conn_put(struct hci_conn *conn) 765static inline void hci_conn_put(struct hci_conn *conn)
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 1558eccb19db..8f1652ed3326 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -948,7 +948,7 @@ void l2cap_logical_cfm(struct l2cap_chan *chan, struct hci_chan *hchan,
948void __l2cap_physical_cfm(struct l2cap_chan *chan, int result); 948void __l2cap_physical_cfm(struct l2cap_chan *chan, int result);
949 949
950void l2cap_conn_shutdown(struct l2cap_conn *conn, int err); 950void l2cap_conn_shutdown(struct l2cap_conn *conn, int err);
951void l2cap_conn_get(struct l2cap_conn *conn); 951struct l2cap_conn *l2cap_conn_get(struct l2cap_conn *conn);
952void l2cap_conn_put(struct l2cap_conn *conn); 952void l2cap_conn_put(struct l2cap_conn *conn);
953 953
954int l2cap_register_user(struct l2cap_conn *conn, struct l2cap_user *user); 954int l2cap_register_user(struct l2cap_conn *conn, struct l2cap_user *user);
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index 6c7ecf116e74..1b7d605706aa 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -915,7 +915,7 @@ static int hidp_session_new(struct hidp_session **out, const bdaddr_t *bdaddr,
915 915
916 /* connection management */ 916 /* connection management */
917 bacpy(&session->bdaddr, bdaddr); 917 bacpy(&session->bdaddr, bdaddr);
918 session->conn = conn; 918 session->conn = l2cap_conn_get(conn);
919 session->user.probe = hidp_session_probe; 919 session->user.probe = hidp_session_probe;
920 session->user.remove = hidp_session_remove; 920 session->user.remove = hidp_session_remove;
921 session->ctrl_sock = ctrl_sock; 921 session->ctrl_sock = ctrl_sock;
@@ -941,13 +941,13 @@ static int hidp_session_new(struct hidp_session **out, const bdaddr_t *bdaddr,
941 if (ret) 941 if (ret)
942 goto err_free; 942 goto err_free;
943 943
944 l2cap_conn_get(session->conn);
945 get_file(session->intr_sock->file); 944 get_file(session->intr_sock->file);
946 get_file(session->ctrl_sock->file); 945 get_file(session->ctrl_sock->file);
947 *out = session; 946 *out = session;
948 return 0; 947 return 0;
949 948
950err_free: 949err_free:
950 l2cap_conn_put(session->conn);
951 kfree(session); 951 kfree(session);
952 return ret; 952 return ret;
953} 953}
@@ -1327,10 +1327,8 @@ int hidp_connection_add(struct hidp_connadd_req *req,
1327 1327
1328 conn = NULL; 1328 conn = NULL;
1329 l2cap_chan_lock(chan); 1329 l2cap_chan_lock(chan);
1330 if (chan->conn) { 1330 if (chan->conn)
1331 l2cap_conn_get(chan->conn); 1331 conn = l2cap_conn_get(chan->conn);
1332 conn = chan->conn;
1333 }
1334 l2cap_chan_unlock(chan); 1332 l2cap_chan_unlock(chan);
1335 1333
1336 if (!conn) 1334 if (!conn)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index a6559225bb50..cb36169ef300 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1695,9 +1695,10 @@ static void l2cap_conn_free(struct kref *ref)
1695 kfree(conn); 1695 kfree(conn);
1696} 1696}
1697 1697
1698void l2cap_conn_get(struct l2cap_conn *conn) 1698struct l2cap_conn *l2cap_conn_get(struct l2cap_conn *conn)
1699{ 1699{
1700 kref_get(&conn->ref); 1700 kref_get(&conn->ref);
1701 return conn;
1701} 1702}
1702EXPORT_SYMBOL(l2cap_conn_get); 1703EXPORT_SYMBOL(l2cap_conn_get);
1703 1704
@@ -6908,8 +6909,7 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon)
6908 6909
6909 kref_init(&conn->ref); 6910 kref_init(&conn->ref);
6910 hcon->l2cap_data = conn; 6911 hcon->l2cap_data = conn;
6911 conn->hcon = hcon; 6912 conn->hcon = hci_conn_get(hcon);
6912 hci_conn_get(conn->hcon);
6913 conn->hchan = hchan; 6913 conn->hchan = hchan;
6914 6914
6915 BT_DBG("hcon %p conn %p hchan %p", hcon, conn, hchan); 6915 BT_DBG("hcon %p conn %p hchan %p", hcon, conn, hchan);