All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: delete the new SCO link if linking it fails
@ 2026-11-04  2:28 Wentao Liang
  2026-11-04  7:12 ` Krzysztof Kozlowski
  2026-11-04  8:46 ` bluez.test.bot
  0 siblings, 2 replies; 3+ messages in thread
From: Wentao Liang @ 2026-11-04  2:28 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz; +Cc: linux-bluetooth

hci_connect_sco() adds a fresh SCO/eSCO connection with
hci_conn_add_unset(), which leaves its hold counter at zero and takes a
reference on the controller. If hci_conn_link() then fails, for example
because the link cannot be allocated, the error path calls
hci_conn_drop() on a connection nobody holds. The counter goes below
zero, the delayed deletion work is never armed, and the connection stays
in the hash with its controller reference until the controller is
unregistered.

Use hci_conn_del() for a connection created here, as the other
hci_conn_add_unset() error paths do, and keep the drop for a connection
that was found in the hash.

Fixes: 06149746e720 ("Bluetooth: hci_conn: Add support for linking multiple hcon")
Cc: stable@vger.kernel.org
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 net/bluetooth/hci_conn.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 29da3fe2b953..660eaf5adf96 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -1896,6 +1896,7 @@ struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
 	struct hci_conn *acl;
 	struct hci_conn *sco;
 	struct hci_link *link;
+	bool new_sco = false;
 
 	acl = hci_connect_acl(hdev, dst, BT_SECURITY_LOW, HCI_AT_NO_BONDING,
 			      CONN_REASON_SCO_CONNECT, timeout);
@@ -1909,12 +1910,19 @@ struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
 			hci_conn_drop(acl);
 			return sco;
 		}
+
+		new_sco = true;
 	}
 
 	link = hci_conn_link(acl, sco);
 	if (!link) {
 		hci_conn_drop(acl);
-		hci_conn_drop(sco);
+
+		if (new_sco)
+			hci_conn_del(sco);
+		else
+			hci_conn_drop(sco);
+
 		return ERR_PTR(-ENOLINK);
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-04  8:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04  2:28 [PATCH] Bluetooth: delete the new SCO link if linking it fails Wentao Liang
2026-11-04  7:12 ` Krzysztof Kozlowski
2026-11-04  8:46 ` bluez.test.bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.