fix(nimble): Prevent crash in deinit when host init was not completed

This commit is contained in:
Rahul Tank
2026-08-26 15:18:26 +05:30
parent 923f273694
commit 135d1aeba7
3 changed files with 35 additions and 2 deletions
+14
View File
@@ -211,6 +211,7 @@ static struct ble_npl_callout ble_hs_timer;
static struct ble_mqueue ble_hs_rx_q;
static struct ble_npl_mutex ble_hs_mutex;
static bool ble_hs_initialized;
#endif // BLE_STATIC_TO_DYNAMIC
STATS_SECT_DECL(ble_hs_stats) ble_hs_stats;
@@ -1040,6 +1041,9 @@ ble_hs_init(void)
#endif
/* Initialize npl variables related to hs flow control */
ble_hs_flow_init();
#if !MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
ble_hs_initialized = true;
#endif
}
/* Transport APIs for HS side */
@@ -1067,6 +1071,16 @@ ble_transport_hs_init(void)
void
ble_hs_deinit(void)
{
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
if (!ble_hs_ctx) {
return;
}
#else
if (!ble_hs_initialized) {
return;
}
ble_hs_initialized = false;
#endif
ble_hs_flow_deinit();
#if BLE_MONITOR
+11
View File
@@ -422,6 +422,17 @@ void nimble_port_run(void)
{
struct ble_npl_event *ev;
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
if (ble_npl_ctx == NULL) {
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "nimble context not initialized, host task exiting");
return;
}
#endif
if (g_eventq_dflt.eventq == NULL) {
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "nimble event queue not initialized, host task exiting");
return;
}
while (1) {
ev = ble_npl_eventq_get(&g_eventq_dflt, BLE_NPL_TIME_FOREVER);
if (ev) {
+10 -2
View File
@@ -270,7 +270,9 @@ npl_freertos_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn,
void
npl_freertos_event_deinit(struct ble_npl_event *ev)
{
BLE_LL_ASSERT(ev->event);
if (!ev->event) {
return;
}
#if OS_MEM_ALLOC
os_memblock_put(&ble_freertos_ev_pool,ev->event);
@@ -321,7 +323,9 @@ npl_freertos_eventq_deinit(struct ble_npl_eventq *evq)
{
struct ble_npl_eventq_freertos *eventq = (struct ble_npl_eventq_freertos *)evq->eventq;
BLE_LL_ASSERT(eventq);
if (!eventq) {
return;
}
vQueueDelete(eventq->q);
#if OS_MEM_ALLOC
os_memblock_put(&ble_freertos_evq_pool,eventq);
@@ -357,6 +361,10 @@ npl_freertos_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
BaseType_t woken;
BaseType_t ret;
if (!eventq) {
return NULL;
}
if (in_isr()) {
BLE_LL_ASSERT(tmo == 0);
ret = xQueueReceiveFromISR(eventq->q, &ev, &woken);