Skip to content

Commit 8d74c91

Browse files
pvVudentz
authored andcommitted
Bluetooth: SCO: fix sco_conn refcounting on sco_conn_ready
sco_conn refcount shall not be incremented a second time if the sk already owns the refcount, so hold only when adding new chan. Add sco_conn_hold() for clarity, as refcnt is never zero here due to the sco_conn_add(). Fixes SCO socket shutdown not actually closing the SCO connection. Fixes: ed95885 ("Bluetooth: SCO: remove the redundant sco_conn_put") Signed-off-by: Pauli Virtanen <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 75ddcd5 commit 8d74c91

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

net/bluetooth/sco.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ static void sco_conn_put(struct sco_conn *conn)
107107
kref_put(&conn->ref, sco_conn_free);
108108
}
109109

110+
static struct sco_conn *sco_conn_hold(struct sco_conn *conn)
111+
{
112+
BT_DBG("conn %p refcnt %u", conn, kref_read(&conn->ref));
113+
114+
kref_get(&conn->ref);
115+
return conn;
116+
}
117+
110118
static struct sco_conn *sco_conn_hold_unless_zero(struct sco_conn *conn)
111119
{
112120
if (!conn)
@@ -1353,6 +1361,7 @@ static void sco_conn_ready(struct sco_conn *conn)
13531361
bacpy(&sco_pi(sk)->src, &conn->hcon->src);
13541362
bacpy(&sco_pi(sk)->dst, &conn->hcon->dst);
13551363

1364+
sco_conn_hold(conn);
13561365
hci_conn_hold(conn->hcon);
13571366
__sco_chan_add(conn, sk, parent);
13581367

@@ -1411,8 +1420,10 @@ static void sco_connect_cfm(struct hci_conn *hcon, __u8 status)
14111420
struct sco_conn *conn;
14121421

14131422
conn = sco_conn_add(hcon);
1414-
if (conn)
1423+
if (conn) {
14151424
sco_conn_ready(conn);
1425+
sco_conn_put(conn);
1426+
}
14161427
} else
14171428
sco_conn_del(hcon, bt_to_errno(status));
14181429
}

0 commit comments

Comments
 (0)