Skip to content

Commit 0525578

Browse files
committed
nimble/host: Rework locking in L2CAP
Main goal here to cleanup how locking is being done in L2CAP code: - avoid double/nested locking - avoid lock-unlock-lock pattern due to public API calls from internal code - provide _nolock variants to be used internally - public API is locked wrapper around _nolock private API - avoid locking in FOO and unlocking in BAR function for code clarify
1 parent f6f9142 commit 0525578

File tree

6 files changed

+255
-220
lines changed

6 files changed

+255
-220
lines changed

nimble/host/src/ble_l2cap.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,13 @@ int
152152
ble_l2cap_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
153153
struct os_mbuf *sdu_rx, ble_l2cap_event_fn *cb, void *cb_arg)
154154
{
155-
return ble_l2cap_sig_coc_connect(conn_handle, psm, mtu, sdu_rx, cb, cb_arg);
155+
int rc;
156+
157+
ble_hs_lock();
158+
rc = ble_l2cap_sig_connect_nolock(conn_handle, psm, mtu, sdu_rx, cb, cb_arg);
159+
ble_hs_unlock();
160+
161+
return rc;
156162
}
157163

158164
int
@@ -183,15 +189,22 @@ ble_l2cap_enhanced_connect(uint16_t conn_handle,
183189
uint8_t num, struct os_mbuf *sdu_rx[],
184190
ble_l2cap_event_fn *cb, void *cb_arg)
185191
{
186-
return ble_l2cap_sig_ecoc_connect(conn_handle, psm, mtu,
187-
num, sdu_rx, cb, cb_arg);
192+
int rc;
193+
194+
ble_hs_lock();
195+
rc = ble_l2cap_sig_ecoc_connect_nolock(conn_handle, psm, mtu, num, sdu_rx,
196+
cb, cb_arg);
197+
ble_hs_unlock();
198+
199+
return rc;
188200
}
189201

190202
int
191203
ble_l2cap_reconfig(struct ble_l2cap_chan *chans[], uint8_t num, uint16_t new_mtu)
192204
{
193205
int i;
194206
uint16_t conn_handle;
207+
int rc;
195208

196209
if (num == 0 || !chans) {
197210
return BLE_HS_EINVAL;
@@ -206,13 +219,23 @@ ble_l2cap_reconfig(struct ble_l2cap_chan *chans[], uint8_t num, uint16_t new_mtu
206219
}
207220
}
208221

209-
return ble_l2cap_sig_coc_reconfig(conn_handle, chans, num, new_mtu);
222+
ble_hs_lock();
223+
rc = ble_l2cap_sig_coc_reconfig_nolock(conn_handle, chans, num, new_mtu);
224+
ble_hs_unlock();
225+
226+
return rc;
210227
}
211228

212229
int
213230
ble_l2cap_disconnect(struct ble_l2cap_chan *chan)
214231
{
215-
return ble_l2cap_sig_disconnect(chan);
232+
int rc;
233+
234+
ble_hs_lock();
235+
rc = ble_l2cap_sig_disconnect_nolock(chan);
236+
ble_hs_unlock();
237+
238+
return rc;
216239
}
217240

218241
/**

nimble/host/src/ble_l2cap_coc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,8 @@ ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
599599

600600
if (chan->coc_tx.credits + credits > 0xFFFF) {
601601
BLE_HS_LOG(INFO, "LE CoC credits overflow...disconnecting\n");
602+
ble_l2cap_sig_disconnect_nolock(chan);
602603
ble_hs_unlock();
603-
ble_l2cap_sig_disconnect(chan);
604604
return;
605605
}
606606

0 commit comments

Comments
 (0)