diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c index 44f6756dc42..24033d48b40 100644 --- a/net/bluetooth/l2cap.c +++ b/net/bluetooth/l2cap.c @@ -541,9 +541,7 @@ static void l2cap_chan_destroy(struct bt_l2cap_chan *chan) /* There could be a writer waiting for credits so return a dummy credit * to wake it up. */ - if (!ch->tx.credits.nsig) { - l2cap_chan_tx_give_credits(ch, 1); - } + l2cap_chan_tx_give_credits(ch, 1); /* Destroy segmented SDU if it exists */ if (ch->_sdu) { @@ -851,7 +849,7 @@ static void le_credits(struct bt_l2cap *l2cap, uint8_t ident, ch = BT_L2CAP_LE_CHAN(chan); - if (ch->tx.credits.nsig + credits > UINT16_MAX) { + if (nano_sem_count_get(&ch->tx.credits) + credits > UINT16_MAX) { BT_ERR("Credits overflow"); bt_l2cap_chan_disconnect(chan); return; @@ -955,12 +953,13 @@ static void l2cap_chan_update_credits(struct bt_l2cap_le_chan *chan) uint16_t credits; /* Only give more credits if it went bellow the defined threshold */ - if (chan->rx.credits.nsig > L2CAP_LE_CREDITS_THRESHOLD) { + if (nano_sem_count_get(&chan->tx.credits) > + L2CAP_LE_CREDITS_THRESHOLD) { goto done; } /* Restore credits */ - credits = L2CAP_LE_MAX_CREDITS - chan->rx.credits.nsig; + credits = L2CAP_LE_MAX_CREDITS - nano_sem_count_get(&chan->tx.credits); l2cap_chan_rx_give_credits(chan, credits); buf = bt_l2cap_create_pdu(&le_sig, 0);