Skip to content

Commit 51bb845

Browse files
jhedbergholtmann
authored andcommitted
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>
1 parent 5477610 commit 51bb845

4 files changed

Lines changed: 10 additions & 11 deletions

File tree

‎include/net/bluetooth/hci_core.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,9 +756,10 @@ void hci_le_conn_failed(struct hci_conn *conn, u8 status);
756756
* _get()/_drop() in it, but require the caller to have a valid ref (FIXME).
757757
*/
758758

759-
static inline void hci_conn_get(struct hci_conn *conn)
759+
static inline struct hci_conn *hci_conn_get(struct hci_conn *conn)
760760
{
761761
get_device(&conn->dev);
762+
return conn;
762763
}
763764

764765
static inline void hci_conn_put(struct hci_conn *conn)

‎include/net/bluetooth/l2cap.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ void l2cap_logical_cfm(struct l2cap_chan *chan, struct hci_chan *hchan,
948948
void __l2cap_physical_cfm(struct l2cap_chan *chan, int result);
949949

950950
void l2cap_conn_shutdown(struct l2cap_conn *conn, int err);
951-
void l2cap_conn_get(struct l2cap_conn *conn);
951+
struct l2cap_conn *l2cap_conn_get(struct l2cap_conn *conn);
952952
void l2cap_conn_put(struct l2cap_conn *conn);
953953

954954
int l2cap_register_user(struct l2cap_conn *conn, struct l2cap_user *user);

‎net/bluetooth/hidp/core.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ static int hidp_session_new(struct hidp_session **out, const bdaddr_t *bdaddr,
915915

916916
/* connection management */
917917
bacpy(&session->bdaddr, bdaddr);
918-
session->conn = conn;
918+
session->conn = l2cap_conn_get(conn);
919919
session->user.probe = hidp_session_probe;
920920
session->user.remove = hidp_session_remove;
921921
session->ctrl_sock = ctrl_sock;
@@ -941,13 +941,13 @@ static int hidp_session_new(struct hidp_session **out, const bdaddr_t *bdaddr,
941941
if (ret)
942942
goto err_free;
943943

944-
l2cap_conn_get(session->conn);
945944
get_file(session->intr_sock->file);
946945
get_file(session->ctrl_sock->file);
947946
*out = session;
948947
return 0;
949948

950949
err_free:
950+
l2cap_conn_put(session->conn);
951951
kfree(session);
952952
return ret;
953953
}
@@ -1327,10 +1327,8 @@ int hidp_connection_add(struct hidp_connadd_req *req,
13271327

13281328
conn = NULL;
13291329
l2cap_chan_lock(chan);
1330-
if (chan->conn) {
1331-
l2cap_conn_get(chan->conn);
1332-
conn = chan->conn;
1333-
}
1330+
if (chan->conn)
1331+
conn = l2cap_conn_get(chan->conn);
13341332
l2cap_chan_unlock(chan);
13351333

13361334
if (!conn)

‎net/bluetooth/l2cap_core.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,9 +1695,10 @@ static void l2cap_conn_free(struct kref *ref)
16951695
kfree(conn);
16961696
}
16971697

1698-
void l2cap_conn_get(struct l2cap_conn *conn)
1698+
struct l2cap_conn *l2cap_conn_get(struct l2cap_conn *conn)
16991699
{
17001700
kref_get(&conn->ref);
1701+
return conn;
17011702
}
17021703
EXPORT_SYMBOL(l2cap_conn_get);
17031704

@@ -6908,8 +6909,7 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon)
69086909

69096910
kref_init(&conn->ref);
69106911
hcon->l2cap_data = conn;
6911-
conn->hcon = hcon;
6912-
hci_conn_get(conn->hcon);
6912+
conn->hcon = hci_conn_get(hcon);
69136913
conn->hchan = hchan;
69146914

69156915
BT_DBG("hcon %p conn %p hchan %p", hcon, conn, hchan);

0 commit comments

Comments
 (0)