mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-19 15:39:53 +00:00
fix(nimble): Prevent crash in deinit when host init was not completed
This commit is contained in:
@@ -213,6 +213,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;
|
||||
@@ -1045,6 +1046,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 */
|
||||
@@ -1092,6 +1096,11 @@ ble_hs_deinit(void)
|
||||
if (!ble_hs_ctx) {
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (!ble_hs_initialized) {
|
||||
return;
|
||||
}
|
||||
ble_hs_initialized = false;
|
||||
#endif
|
||||
ble_hs_flow_deinit();
|
||||
|
||||
|
||||
@@ -510,6 +510,22 @@ 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 CONFIG_BT_DUAL_MODE_ARCH
|
||||
if (g_eventq_dflt.eventq.eventq == NULL) {
|
||||
#else
|
||||
if (g_eventq_dflt.eventq == NULL) {
|
||||
#endif
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "nimble event queue not initialized, host task exiting");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Cache addresses before entering the loop. When BLE_STATIC_TO_DYNAMIC is
|
||||
* enabled these macros dereference ble_npl_ctx; caching prevents a race
|
||||
* where ble_npl_ctx is freed between the stop-event callback returning and
|
||||
|
||||
@@ -353,7 +353,9 @@ npl_freertos_eventq_deinit(struct ble_npl_eventq *evq)
|
||||
struct ble_npl_eventq_freertos *eventq = (struct ble_npl_eventq_freertos *)evq->eventq;
|
||||
struct ble_npl_event *ev;
|
||||
|
||||
BLE_LL_ASSERT(eventq);
|
||||
if (!eventq) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Drain the queue and clear the queued flag on all events */
|
||||
while (uxQueueMessagesWaiting(eventq->q) > 0) {
|
||||
@@ -518,6 +520,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);
|
||||
ret = xQueueReceiveFromISR(eventq->q, &ev, &woken);
|
||||
|
||||
Reference in New Issue
Block a user