Skip to content

Commit cc098c6

Browse files
MarekPietarlubos
authored andcommitted
[nrf noup] bluetooth: conn: Skip buffer ref count check in send_buf
If ATT sent callback is delayed until data transmission is done by BLE controller, the transmitted buffer may have an additional reference. The reference is used to extend lifetime of the net buffer until the data transmission is confirmed by ACK of the remote. send_buf function can be called multiple times, if buffer has to be fragmented over HCI. In that case, the callback is provided as an argument only for the last transmitted fragment. The `buf->ref == 1` check is skipped because it's impossible to properly validate number of references for the sent fragments if buffers may have the additional reference. Jira: NCSDK-28624 Signed-off-by: Marek Pieta <[email protected]> (cherry picked from commit 2c09574)
1 parent 90daf74 commit cc098c6

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

subsys/bluetooth/host/conn.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -702,19 +702,27 @@ static int send_buf(struct bt_conn *conn, struct net_buf *buf,
702702

703703
uint16_t frag_len = MIN(conn_mtu(conn), len);
704704

705-
/* Check that buf->ref is 1 or 2. It would be 1 if this was
706-
* the only reference (e.g. buf was removed from the conn
707-
* tx_queue). It would be 2 if the tx_data_pull kept it on
708-
* the tx_queue for segmentation.
705+
/* If ATT sent callback is delayed until data transmission
706+
* is done by BLE controller, the transmitted buffer may
707+
* have an additional reference. The reference is used to
708+
* extend lifetime of the net buffer until the data
709+
* transmission is confirmed by ACK of the remote.
709710
*
710-
* Allow for an additional buffer reference if callback is
711-
* provided. This can be used to extend lifetime of the net
712-
* buffer until the data transmission is confirmed by ACK of
713-
* the remote.
711+
* send_buf function can be called multiple times, if buffer
712+
* has to be fragmented over HCI. In that case, the callback
713+
* is provided as an argument only for the last transmitted
714+
* fragment. The `buf->ref == 1` (or 2) check is skipped
715+
* because it's impossible to properly validate number of
716+
* references for the sent fragments if buffers may have the
717+
* additional reference.
718+
*
719+
* Otherwise, check that buf->ref is 1 or 2. It would be 1
720+
* if this was the only reference (e.g. buf was removed from
721+
* the conn tx_queue). It would be 2 if the tx_data_pull
722+
* kept it on the tx_queue for segmentation.
714723
*/
715-
if (buf->ref > 2 + (cb ? 1 : 0)) {
716-
__ASSERT_NO_MSG(false);
717-
}
724+
__ASSERT_NO_MSG(IS_ENABLED(CONFIG_BT_ATT_SENT_CB_AFTER_TX) || (buf->ref == 1) ||
725+
(buf->ref == 2));
718726

719727
/* The reference is always transferred to the frag, so when
720728
* the frag is destroyed, the parent reference is decremented.

0 commit comments

Comments
 (0)