Skip to content

Commit 3c1ca93

Browse files
jori-nordiccarlescufi
authored andcommitted
Bluetooth: host: l2cap: don't send too much credits
There was an edge-case where we were sending back too much credits, add a check so we can't do that anymore. Signed-off-by: Jonathan Rico <[email protected]>
1 parent 1c8fe67 commit 3c1ca93

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

subsys/bluetooth/host/l2cap.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,7 @@ static void l2cap_chan_send_credits(struct bt_l2cap_le_chan *chan,
22582258
struct net_buf *buf, uint16_t credits)
22592259
{
22602260
struct bt_l2cap_le_credits *ev;
2261+
uint16_t old_credits;
22612262

22622263
__ASSERT_NO_MSG(bt_l2cap_chan_get_state(&chan->chan) == BT_L2CAP_CONNECTED);
22632264

@@ -2266,6 +2267,12 @@ static void l2cap_chan_send_credits(struct bt_l2cap_le_chan *chan,
22662267
credits = chan->rx.init_credits;
22672268
}
22682269

2270+
/* Don't send back more than the initial amount. */
2271+
old_credits = atomic_get(&chan->rx.credits);
2272+
if (credits + old_credits > chan->rx.init_credits) {
2273+
credits = chan->rx.init_credits - old_credits;
2274+
}
2275+
22692276
buf = l2cap_create_le_sig_pdu(buf, BT_L2CAP_LE_CREDITS, get_ident(),
22702277
sizeof(*ev));
22712278
if (!buf) {
@@ -2298,6 +2305,8 @@ static void l2cap_chan_update_credits(struct bt_l2cap_le_chan *chan,
22982305
credits = ((chan->_sdu_len - net_buf_frags_len(buf)) +
22992306
(chan->rx.mps - 1)) / chan->rx.mps;
23002307

2308+
BT_DBG("cred %d old %d", credits, (int)old_credits);
2309+
23012310
if (credits < old_credits) {
23022311
return;
23032312
}

0 commit comments

Comments
 (0)