Skip to content

Commit d14ec92

Browse files
MarekPietajukkar
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 cc098c6)
1 parent eb046f3 commit d14ec92

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
@@ -711,19 +711,27 @@ static int send_buf(struct bt_conn *conn, struct net_buf *buf,
711711

712712
uint16_t frag_len = MIN(conn_mtu(conn), len);
713713

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

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

0 commit comments

Comments
 (0)