Bluetooth: L2CAP: Fix using s16_t to represent credits
Credits are 2 octects long so an s16_t positive portion can only half to the theorical maximum number of credits, so instead this uses u16_t and do a bound check instead of checking for negative values. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
4ff711d8a5
commit
2cfef8cd77
1 changed files with 6 additions and 3 deletions
|
@ -1599,16 +1599,19 @@ static void l2cap_chan_send_credits(struct bt_l2cap_le_chan *chan,
|
||||||
static void l2cap_chan_update_credits(struct bt_l2cap_le_chan *chan,
|
static void l2cap_chan_update_credits(struct bt_l2cap_le_chan *chan,
|
||||||
struct net_buf *buf)
|
struct net_buf *buf)
|
||||||
{
|
{
|
||||||
s16_t credits;
|
u16_t credits;
|
||||||
|
atomic_val_t old_credits = atomic_get(&chan->rx.credits);
|
||||||
|
|
||||||
/* Restore enough credits to complete the sdu */
|
/* Restore enough credits to complete the sdu */
|
||||||
credits = ((chan->_sdu_len - net_buf_frags_len(buf)) +
|
credits = ((chan->_sdu_len - net_buf_frags_len(buf)) +
|
||||||
(chan->rx.mps - 1)) / chan->rx.mps;
|
(chan->rx.mps - 1)) / chan->rx.mps;
|
||||||
credits -= atomic_get(&chan->rx.credits);
|
|
||||||
if (credits <= 0) {
|
if (credits < old_credits) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
credits -= old_credits;
|
||||||
|
|
||||||
l2cap_chan_send_credits(chan, buf, credits);
|
l2cap_chan_send_credits(chan, buf, credits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue