mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-10-15 18:17:23 +00:00
fix(nimble): Prevent crash in deinit when host init was not completed
This commit is contained in:
@@ -212,6 +212,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;
|
||||
@@ -1087,6 +1088,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 */
|
||||
@@ -1134,6 +1138,11 @@ ble_hs_deinit(void)
|
||||
if (ble_hs_ctx == NULL) {
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (!ble_hs_initialized) {
|
||||
return;
|
||||
}
|
||||
ble_hs_initialized = false;
|
||||
#endif
|
||||
|
||||
ble_hs_flow_deinit();
|
||||
|
||||
@@ -457,6 +457,18 @@ IRAM_ATTR
|
||||
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;
|
||||
}
|
||||
|
||||
/* Snapshot stop_ev and stop_sem addresses before entering the loop.
|
||||
* When BLE_STATIC_TO_DYNAMIC is enabled, after ble_npl_sem_release(stop_sem)
|
||||
* at the end of stop-event handling, the caller of nimble_port_stop() can
|
||||
|
||||
@@ -461,6 +461,10 @@ npl_freertos_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
|
||||
BaseType_t woken = pdFALSE;
|
||||
BaseType_t ret;
|
||||
|
||||
if (!eventq) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (in_isr()) {
|
||||
BLE_LL_ASSERT(tmo == 0);
|
||||
woken = pdFALSE;
|
||||
|
||||
Reference in New Issue
Block a user