]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Bluetooth: SCO: fix sco_conn refcounting on sco_conn_ready
authorPauli Virtanen <pav@iki.fi>
Thu, 27 Feb 2025 21:28:15 +0000 (23:28 +0200)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 7 Mar 2025 17:43:29 +0000 (12:43 -0500)
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: ed9588554943 ("Bluetooth: SCO: remove the redundant sco_conn_put")
Signed-off-by: Pauli Virtanen <pav@iki.fi>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
net/bluetooth/sco.c

index aa7bfe26cb40f2b489b871ad4db7e0353bc42ecb..ed6846864ea939450dbcf6ab9350734d3a162bfe 100644 (file)
@@ -107,6 +107,14 @@ static void sco_conn_put(struct sco_conn *conn)
        kref_put(&conn->ref, sco_conn_free);
 }
 
+static struct sco_conn *sco_conn_hold(struct sco_conn *conn)
+{
+       BT_DBG("conn %p refcnt %u", conn, kref_read(&conn->ref));
+
+       kref_get(&conn->ref);
+       return conn;
+}
+
 static struct sco_conn *sco_conn_hold_unless_zero(struct sco_conn *conn)
 {
        if (!conn)
@@ -1353,6 +1361,7 @@ static void sco_conn_ready(struct sco_conn *conn)
                bacpy(&sco_pi(sk)->src, &conn->hcon->src);
                bacpy(&sco_pi(sk)->dst, &conn->hcon->dst);
 
+               sco_conn_hold(conn);
                hci_conn_hold(conn->hcon);
                __sco_chan_add(conn, sk, parent);
 
@@ -1411,8 +1420,10 @@ static void sco_connect_cfm(struct hci_conn *hcon, __u8 status)
                struct sco_conn *conn;
 
                conn = sco_conn_add(hcon);
-               if (conn)
+               if (conn) {
                        sco_conn_ready(conn);
+                       sco_conn_put(conn);
+               }
        } else
                sco_conn_del(hcon, bt_to_errno(status));
 }