Skip to content

Commit fc9c54f

Browse files
jplexergmarull
authored andcommitted
fw/services/bluetooth: fix deadlock in evaluate_pairing_refcount
The evaluate_pairing_refcount callback was calling gap_le_slave_is_discoverable() which acquires bt_lock from the System Task context. This caused a deadlock when the Launcher Task already held bt_lock while waiting for ble_hs_mutex, resulting in a watchdog timeout. Fix by caching the BLE discoverable state locally instead of querying it via gap_le_slave_is_discoverable(), eliminating the cross-task lock acquisition. The cached state maintains the same optimization (avoiding redundant calls to gap_le_slave_set_discoverable) without the deadlock risk. Signed-off-by: Joshua Jun <[email protected]>
1 parent deeb8db commit fc9c54f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/fw/services/common/bluetooth/pairability.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ static void prv_pairability_timer_cb(void *unused);
2222

2323
static int s_allow_bt_pairing_refcount = 0;
2424
static int s_allow_ble_pairing_refcount = 0;
25+
static bool s_last_ble_discoverable_state = false;
2526

2627
static RegularTimerInfo s_pairability_timer_info = {
2728
.cb = prv_pairability_timer_cb,
@@ -40,13 +41,14 @@ static void evaluate_pairing_refcount(void *data) {
4041
bool is_ble_pairable_and_discoverable = (s_allow_ble_pairing_refcount > 0);
4142

4243
bt_driver_le_pairability_set_enabled(is_ble_pairable_and_discoverable);
43-
if (gap_le_slave_is_discoverable() != is_ble_pairable_and_discoverable) {
44+
if (s_last_ble_discoverable_state != is_ble_pairable_and_discoverable) {
4445
if (is_ble_pairable_and_discoverable) {
4546
bt_local_addr_pause_cycling();
4647
} else {
4748
bt_local_addr_resume_cycling();
4849
}
4950
gap_le_slave_set_discoverable(is_ble_pairable_and_discoverable);
51+
s_last_ble_discoverable_state = is_ble_pairable_and_discoverable;
5052
}
5153

5254
if (bt_driver_supports_bt_classic()) {

0 commit comments

Comments
 (0)