Skip to contentSkip to conversation

Bluetooth: ISO: Don't initiate CIS connections if there are no buffers

PATCH Superseded Luiz Augusto von Dentz 3 participants 7 messages Aug 12, 2025

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v2 1/3 Bluetooth: ISO: Don't initiate CIS connections if there are no buffers

From: Luiz Augusto von Dentz <[email protected]>

If the controller has no buffers left return -ENOBUFF to indicate that iso_cnt might be out of sync.

---
 net/bluetooth/iso.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/bluetooth/iso.c +7 -0
index 5ce823ca3aaf..dff3fc4917d6 100644
@@ -458,6 +458,13 @@ static int iso_connect_cis(struct sock *sk)
 		goto unlock;
 	}
 
+	/* Check if there are available buffers for output/TX. */
+	if (iso_pi(sk)->qos.ucast.out.sdu && !hci_conn_num(hdev, CIS_LINK) &&
+	    (hdev->iso_pkts && !hdev->iso_cnt)) {
+		err = -ENOBUFS;
+		goto unlock;
+	}
+
 	/* Just bind if DEFER_SETUP has been set */
 	if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
 		hcon = hci_bind_cis(hdev, &iso_pi(sk)->dst,
Signature · 1 line
2.50.1
author maintainer
#1 lore raw

PATCH v2 2/3 Bluetooth: HCI: Fix using LE/ACL buffers for ISO packets

From: Luiz Augusto von Dentz <[email protected]>

ISO packets shall not use LE/ACL buffer pool, that feature seem to be exclusive to LE-ACL only.

---
 net/bluetooth/hci_conn.c  | 26 +++++++++++---------------
 net/bluetooth/hci_core.c  |  3 +--
 net/bluetooth/hci_event.c | 16 +++-------------
 3 files changed, 15 insertions(+), 30 deletions(-)
net/bluetooth/hci_conn.c +11 -15
index 7a879290dd28..e6cea51b3eab 100644
@@ -1152,28 +1152,24 @@ void hci_conn_del(struct hci_conn *conn)
 	disable_delayed_work_sync(&conn->auto_accept_work);
 	disable_delayed_work_sync(&conn->idle_work);
 
-	if (conn->type == ACL_LINK) {
-		/* Unacked frames */
+	/* Handle unnacked frames */
+	switch (conn->type) {
+	case ACL_LINK:
 		hdev->acl_cnt += conn->sent;
-	} else if (conn->type == LE_LINK) {
+		break;
+	case LE_LINK:
 		cancel_delayed_work(&conn->le_conn_timeout);
 
 		if (hdev->le_pkts)
 			hdev->le_cnt += conn->sent;
 		else
 			hdev->acl_cnt += conn->sent;
-	} else {
-		/* Unacked ISO frames */
-		if (conn->type == CIS_LINK ||
-		    conn->type == BIS_LINK ||
-		    conn->type == PA_LINK) {
-			if (hdev->iso_pkts)
-				hdev->iso_cnt += conn->sent;
-			else if (hdev->le_pkts)
-				hdev->le_cnt += conn->sent;
-			else
-				hdev->acl_cnt += conn->sent;
-		}
+		break;
+	case CIS_LINK:
+	case BIS_LINK:
+	case PA_LINK:
+		hdev->iso_cnt += conn->sent;
+		break;
 	}
 
 	skb_queue_purge(&conn->data_q);
net/bluetooth/hci_core.c +1 -2
index 55e0722fd066..eb09f80a3243 100644
@@ -3759,8 +3759,7 @@ static void hci_sched_iso(struct hci_dev *hdev, __u8 type)
 	if (!hci_conn_num(hdev, type))
 		return;
 
-	cnt = hdev->iso_pkts ? &hdev->iso_cnt :
-		hdev->le_pkts ? &hdev->le_cnt : &hdev->acl_cnt;
+	cnt = &hdev->iso_cnt;
 	while (*cnt && (conn = hci_low_sent(hdev, type, &quote))) {
 		while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
 			BT_DBG("skb %p len %d", skb, skb->len);
net/bluetooth/hci_event.c +3 -13
index fe7cdd67ad2a..1686680a38c8 100644
@@ -4433,19 +4433,9 @@ static void hci_num_comp_pkts_evt(struct hci_dev *hdev, void *data,
 		case CIS_LINK:
 		case BIS_LINK:
 		case PA_LINK:
-			if (hdev->iso_pkts) {
-				hdev->iso_cnt += count;
-				if (hdev->iso_cnt > hdev->iso_pkts)
-					hdev->iso_cnt = hdev->iso_pkts;
-			} else if (hdev->le_pkts) {
-				hdev->le_cnt += count;
-				if (hdev->le_cnt > hdev->le_pkts)
-					hdev->le_cnt = hdev->le_pkts;
-			} else {
-				hdev->acl_cnt += count;
-				if (hdev->acl_cnt > hdev->acl_pkts)
-					hdev->acl_cnt = hdev->acl_pkts;
-			}
+			hdev->iso_cnt += count;
+			if (hdev->iso_cnt > hdev->iso_pkts)
+				hdev->iso_cnt = hdev->iso_pkts;
 			break;
 
 		default:
Signature · 1 line
2.50.1
author maintainer
#2 lore raw

PATCH v2 3/3 Bluetooth: hci_conn: Make unacked packet handling more robust

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This attempts to make unacked packet handling more robust by detecting if there are no connections left then restore all buffers of the respective pool.

---
 net/bluetooth/hci_conn.c | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)
net/bluetooth/hci_conn.c +28 -6
index e6cea51b3eab..4bd2e4cd477f 100644
@@ -1152,22 +1152,44 @@ void hci_conn_del(struct hci_conn *conn)
 	disable_delayed_work_sync(&conn->auto_accept_work);
 	disable_delayed_work_sync(&conn->idle_work);
 
-	/* Handle unnacked frames */
+	/* Handle unnacked frames:
+	 *
+	 * - In case there are no connection restore all buffers to the pool
+	 * - Otherwise restore just the buffers considered in transit for the
+	 *   hci_conn
+	 */
 	switch (conn->type) {
 	case ACL_LINK:
-		hdev->acl_cnt += conn->sent;
+		if (!hci_conn_num(hdev, ACL_LINK))
+			hdev->acl_cnt = hdev->acl_pkts;
+		else
+			hdev->acl_cnt += conn->sent;
 		break;
 	case LE_LINK:
 		cancel_delayed_work(&conn->le_conn_timeout);
 
-		if (hdev->le_pkts)
-			hdev->le_cnt += conn->sent;
-		else
-			hdev->acl_cnt += conn->sent;
+		if (hdev->le_pkts) {
+			if (!hci_conn_num(hdev, LE_LINK))
+				hdev->le_cnt = hdev->le_pkts;
+			else
+				hdev->le_cnt += conn->sent;
+		} else {
+			if (!hci_conn_num(hdev, LE_LINK) &&
+			    !hci_conn_num(hdev, ACL_LINK))
+				hdev->acl_cnt = hdev->acl_pkts;
+			else
+				hdev->acl_cnt += conn->sent;
+		}
 		break;
 	case CIS_LINK:
 	case BIS_LINK:
 	case PA_LINK:
+		if (!hci_conn_num(hdev, CIS_LINK) &&
+		    !hci_conn_num(hdev, BIS_LINK) &&
+		    !hci_conn_num(hdev, PA_LINK))
+			hdev->iso_cnt = hdev->iso_pkts;
+		else
+			hdev->iso_cnt += conn->sent;
 		hdev->iso_cnt += conn->sent;
 		break;
 	}
Signature · 1 line
2.50.1
#3 lore raw

Re: [PATCH v2 3/3] Bluetooth: hci_conn: Make unacked packet handling more robust

Dear Luiz,

Thank you for your patch.

Am 12.08.25 um 21:53 schrieb Luiz Augusto von Dentz:

Quoted 5 lines

From: Luiz Augusto von Dentz <[email protected]>

This attempts to make unacked packet handling more robust by detecting if there are no connections left then restore all buffers of the respective pool.

Did you find this in code review, or was a bug reported?

Quoted 50 lines
---
  net/bluetooth/hci_conn.c | 34 ++++++++++++++++++++++++++++------
  1 file changed, 28 insertions(+), 6 deletions(-)
net/bluetooth/hci_conn.c +22 -6
index e6cea51b3eab..4bd2e4cd477f 100644
@@ -1152,22 +1152,44 @@ void hci_conn_del(struct hci_conn *conn)
  	disable_delayed_work_sync(&conn->auto_accept_work);
  	disable_delayed_work_sync(&conn->idle_work);
 
-	/* Handle unnacked frames */
+	/* Handle unnacked frames:
+	 *
+	 * - In case there are no connection restore all buffers to the pool
+	 * - Otherwise restore just the buffers considered in transit for the
+	 *   hci_conn
+	 */
  	switch (conn->type) {
  	case ACL_LINK:
-		hdev->acl_cnt += conn->sent;
+		if (!hci_conn_num(hdev, ACL_LINK))
+			hdev->acl_cnt = hdev->acl_pkts;
+		else
+			hdev->acl_cnt += conn->sent;
  		break;
  	case LE_LINK:
  		cancel_delayed_work(&conn->le_conn_timeout);
 
-		if (hdev->le_pkts)
-			hdev->le_cnt += conn->sent;
-		else
-			hdev->acl_cnt += conn->sent;
+		if (hdev->le_pkts) {
+			if (!hci_conn_num(hdev, LE_LINK))
+				hdev->le_cnt = hdev->le_pkts;
+			else
+				hdev->le_cnt += conn->sent;
+		} else {
+			if (!hci_conn_num(hdev, LE_LINK) &&
+			    !hci_conn_num(hdev, ACL_LINK))
+				hdev->acl_cnt = hdev->acl_pkts;
+			else
+				hdev->acl_cnt += conn->sent;
+		}
  		break;
  	case CIS_LINK:
  	case BIS_LINK:

net/bluetooth/hci_conn.c void hci_conn_del(struct hci_conn *conn) · line 1195

Quoted 10 lines
net/bluetooth/hci_conn.c +6 -0
  	case PA_LINK:
+		if (!hci_conn_num(hdev, CIS_LINK) &&
+		    !hci_conn_num(hdev, BIS_LINK) &&
+		    !hci_conn_num(hdev, PA_LINK))
+			hdev->iso_cnt = hdev->iso_pkts;
+		else
+			hdev->iso_cnt += conn->sent;
  		hdev->iso_cnt += conn->sent;
  		break;
  	}

Kind regards,

Paul

author maintainer
#4 lore raw

Re: [PATCH v2 3/3] Bluetooth: hci_conn: Make unacked packet handling more robust

Hi Paul,

Quoted 6 lines · Paul Menzel

Dear Luiz,

Thank you for your patch.

Quoted 8 lines

Am 12.08.25 um 21:53 schrieb Luiz Augusto von Dentz:

Quoted 5 lines

From: Luiz Augusto von Dentz <[email protected]>

This attempts to make unacked packet handling more robust by detecting if there are no connections left then restore all buffers of the respective pool.

Did you find this in code review, or was a bug reported?

Internal testing has run into a problem where some packets are never TX for some reason, we are still accessing if this is going to help but it is not an actual fix and more of a way to improve the handling of unacked packets.

Now I'm curious, why this sort of question seem to be recurring, we do encourage as much details as possible, but I don't think we ever said that it is required to disclose what sort of test or bug report it came from, especially if they come from internal testing which cannot be referenced anyway, so was there anything unclear with the commit message?

Quoted 65 lines
Quoted 50 lines
---
  net/bluetooth/hci_conn.c | 34 ++++++++++++++++++++++++++++------
  1 file changed, 28 insertions(+), 6 deletions(-)
net/bluetooth/hci_conn.c +22 -6
index e6cea51b3eab..4bd2e4cd477f 100644
@@ -1152,22 +1152,44 @@ void hci_conn_del(struct hci_conn *conn)
      disable_delayed_work_sync(&conn->auto_accept_work);
      disable_delayed_work_sync(&conn->idle_work);
 
-     /* Handle unnacked frames */
+     /* Handle unnacked frames:
+      *
+      * - In case there are no connection restore all buffers to the pool
+      * - Otherwise restore just the buffers considered in transit for the
+      *   hci_conn
+      */
      switch (conn->type) {
      case ACL_LINK:
-             hdev->acl_cnt += conn->sent;
+             if (!hci_conn_num(hdev, ACL_LINK))
+                     hdev->acl_cnt = hdev->acl_pkts;
+             else
+                     hdev->acl_cnt += conn->sent;
              break;
      case LE_LINK:
              cancel_delayed_work(&conn->le_conn_timeout);
 
-             if (hdev->le_pkts)
-                     hdev->le_cnt += conn->sent;
-             else
-                     hdev->acl_cnt += conn->sent;
+             if (hdev->le_pkts) {
+                     if (!hci_conn_num(hdev, LE_LINK))
+                             hdev->le_cnt = hdev->le_pkts;
+                     else
+                             hdev->le_cnt += conn->sent;
+             } else {
+                     if (!hci_conn_num(hdev, LE_LINK) &&
+                         !hci_conn_num(hdev, ACL_LINK))
+                             hdev->acl_cnt = hdev->acl_pkts;
+                     else
+                             hdev->acl_cnt += conn->sent;
+             }
              break;
      case CIS_LINK:
      case BIS_LINK:

net/bluetooth/hci_conn.c void hci_conn_del(struct hci_conn *conn) · line 1195

Quoted 10 lines
net/bluetooth/hci_conn.c +6 -0
      case PA_LINK:
+             if (!hci_conn_num(hdev, CIS_LINK) &&
+                 !hci_conn_num(hdev, BIS_LINK) &&
+                 !hci_conn_num(hdev, PA_LINK))
+                     hdev->iso_cnt = hdev->iso_pkts;
+             else
+                     hdev->iso_cnt += conn->sent;
              hdev->iso_cnt += conn->sent;
              break;
      }

Kind regards,

Paul

Signature · 1 line
Luiz Augusto von Dentz
#5 lore raw

Re: [PATCH v2 3/3] Bluetooth: hci_conn: Make unacked packet handling more robust

Dear Luiz,

Am 12.08.25 um 22:29 schrieb Luiz Augusto von Dentz:

Quoted 16 lines · Paul Menzel
Quoted 9 lines

Am 12.08.25 um 21:53 schrieb Luiz Augusto von Dentz:

Quoted 5 lines

From: Luiz Augusto von Dentz <[email protected]>

This attempts to make unacked packet handling more robust by detecting if there are no connections left then restore all buffers of the respective pool.

Did you find this in code review, or was a bug reported?

Internal testing has run into a problem where some packets are never TX for some reason, we are still accessing if this is going to help but it is not an actual fix and more of a way to improve the handling of unacked packets.

Quoted 6 lines

Now I'm curious, why this sort of question seem to be recurring, we do encourage as much details as possible, but I don't think we ever said that it is required to disclose what sort of test or bug report it came from, especially if they come from internal testing which cannot be referenced anyway, so was there anything unclear with the commit message?

Kind of:

1. “attempt” sounds to me like, that you tried to fix something, but are not actually sure.

2. In the end, the devices need to work, so knowing how to verify a fix – myself for example – is always helpful in my opinion, so I often ask for reproducers and tests.

Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
---
   net/bluetooth/hci_conn.c | 34 ++++++++++++++++++++++++++++------
   1 file changed, 28 insertions(+), 6 deletions(-)
net/bluetooth/hci_conn.c +23 -6
index e6cea51b3eab..4bd2e4cd477f 100644
@@ -1152,22 +1152,44 @@ void hci_conn_del(struct hci_conn *conn)
       disable_delayed_work_sync(&conn->auto_accept_work);
       disable_delayed_work_sync(&conn->idle_work);
 
-     /* Handle unnacked frames */
+     /* Handle unnacked frames:
+      *
+      * - In case there are no connection restore all buffers to the pool
+      * - Otherwise restore just the buffers considered in transit for the
+      *   hci_conn
+      */
       switch (conn->type) {
       case ACL_LINK:
-             hdev->acl_cnt += conn->sent;
+             if (!hci_conn_num(hdev, ACL_LINK))
+                     hdev->acl_cnt = hdev->acl_pkts;
+             else
+                     hdev->acl_cnt += conn->sent;
               break;
       case LE_LINK:
               cancel_delayed_work(&conn->le_conn_timeout);
 
-             if (hdev->le_pkts)
-                     hdev->le_cnt += conn->sent;
-             else
-                     hdev->acl_cnt += conn->sent;
+             if (hdev->le_pkts) {
+                     if (!hci_conn_num(hdev, LE_LINK))
+                             hdev->le_cnt = hdev->le_pkts;
+                     else
+                             hdev->le_cnt += conn->sent;
+             } else {
+                     if (!hci_conn_num(hdev, LE_LINK) &&
+                         !hci_conn_num(hdev, ACL_LINK))
+                             hdev->acl_cnt = hdev->acl_pkts;
+                     else
+                             hdev->acl_cnt += conn->sent;
+             }
               break;
       case CIS_LINK:
       case BIS_LINK:
       case PA_LINK:
+             if (!hci_conn_num(hdev, CIS_LINK) &&
Quoted 8 lines
Quoted 8 lines

net/bluetooth/hci_conn.c void hci_conn_del(struct hci_conn *conn) · line 1195

Quoted 8 lines
net/bluetooth/hci_conn.c +5 -0
+                 !hci_conn_num(hdev, BIS_LINK) &&
+                 !hci_conn_num(hdev, PA_LINK))
+                     hdev->iso_cnt = hdev->iso_pkts;
+             else
+                     hdev->iso_cnt += conn->sent;
               hdev->iso_cnt += conn->sent;
               break;
       }

Kind regards,

Paul

#6 lore raw
In reply to Luiz Augusto von Dentz

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=990709

---Test result---

Test Summary:

CheckPatch                    PENDING   0.35 seconds
GitLint                       PENDING   0.27 seconds
SubjectPrefix                 PASS      0.34 seconds
BuildKernel                   PASS      23.92 seconds
CheckAllWarning               PASS      26.53 seconds
CheckSparse                   WARNING   29.98 seconds
BuildKernel32                 PASS      23.96 seconds
TestRunnerSetup               PASS      476.08 seconds
TestRunner_l2cap-tester       PASS      24.64 seconds
TestRunner_iso-tester         PASS      40.47 seconds
TestRunner_bnep-tester        PASS      5.92 seconds
TestRunner_mgmt-tester        FAIL      129.29 seconds
TestRunner_rfcomm-tester      PASS      9.30 seconds
TestRunner_sco-tester         PASS      14.50 seconds
TestRunner_ioctl-tester       PASS      9.93 seconds
TestRunner_mesh-tester        FAIL      11.50 seconds
TestRunner_smp-tester         PASS      8.60 seconds
TestRunner_userchan-tester    PASS      6.19 seconds
IncrementalBuild              PENDING   0.46 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:
net/bluetooth/hci_core.c:85:9: warning: context imbalance in '__hci_dev_get' - different lock contexts for basic blocknet/bluetooth/hci_core.c: note: in included file (through include/linux/notifier.h, include/linux/memory_hotplug.h, include/linux/mmzone.h, include/linux/gfp.h, include/linux/xarray.h, include/linux/radix-tree.h, ...):net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 490, Passed: 483 (98.6%), Failed: 3, Not Run: 4

Failed Test Cases

Add Ext Advertising - Success 22 (LE -> off, Remove) Failed       0.126 seconds
Set Device ID - Power off and Power on               Failed       0.110 seconds
Set Device ID - SSP off and Power on                 Failed       0.112 seconds

##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0

Failed Test Cases

Mesh - Send cancel - 1                               Timed out    2.107 seconds
Mesh - Send cancel - 2                               Timed out    1.998 seconds

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

---
Regards,
Linux Bluetooth