From d231b25bc4d6c0d3d6f2c73114e5bd7b92b826e8 Mon Sep 17 00:00:00 2001 From: wangcheng Date: Wed, 13 May 2020 20:11:57 +0800 Subject: [PATCH] fix bta_dm_deinit_cb crash --- components/bt/host/bluedroid/bta/dm/bta_dm_act.c | 3 +++ .../bt/host/bluedroid/bta/dm/include/bta_dm_int.h | 3 ++- components/bt/host/bluedroid/btc/core/btc_main.c | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c index 0c31947c4..8706b1991 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c @@ -334,6 +334,9 @@ void bta_dm_deinit_cb(void) } #endif memset(&bta_dm_cb, 0, sizeof(bta_dm_cb)); +#if BTA_DYNAMIC_MEMORY + xSemaphoreGive(deinit_semaphore); +#endif /* #if BTA_DYNAMIC_MEMORY */ } /******************************************************************************* diff --git a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h index c87708e35..657345377 100644 --- a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h +++ b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h @@ -25,7 +25,7 @@ #define BTA_DM_INT_H #include "common/bt_target.h" - +#include "freertos/semphr.h" #if (BLE_INCLUDED == TRUE && (defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE)) #include "bta/bta_gatt_api.h" #endif @@ -1236,6 +1236,7 @@ extern tBTA_DM_DI_CB bta_dm_di_cb; #else extern tBTA_DM_DI_CB *bta_dm_di_cb_ptr; #define bta_dm_di_cb (*bta_dm_di_cb_ptr) +SemaphoreHandle_t deinit_semaphore; #endif #if BTA_DYNAMIC_MEMORY == FALSE diff --git a/components/bt/host/bluedroid/btc/core/btc_main.c b/components/bt/host/bluedroid/btc/core/btc_main.c index c91aedfb1..c92c34b5e 100644 --- a/components/bt/host/bluedroid/btc/core/btc_main.c +++ b/components/bt/host/bluedroid/btc/core/btc_main.c @@ -70,11 +70,18 @@ static void btc_init_bluetooth(void) btc_dm_load_ble_local_keys(); #endif ///BLE_INCLUDED == TRUE #endif /* #if (SMP_INCLUDED) */ +#if BTA_DYNAMIC_MEMORY + deinit_semaphore = xSemaphoreCreateBinary(); +#endif /* #if BTA_DYNAMIC_MEMORY */ } static void btc_deinit_bluetooth(void) { + /* Wait for the disable operation to complete */ +#if BTA_DYNAMIC_MEMORY + xSemaphoreTake(deinit_semaphore, BTA_DISABLE_DELAY / portTICK_PERIOD_MS); +#endif /* #if BTA_DYNAMIC_MEMORY */ #if (BLE_INCLUDED == TRUE) btc_gap_ble_deinit(); #endif ///BLE_INCLUDED == TRUE @@ -92,6 +99,10 @@ static void btc_deinit_bluetooth(void) osi_alarm_deinit(); osi_alarm_delete_mux(); future_ready(*btc_main_get_future_p(BTC_MAIN_DEINIT_FUTURE), FUTURE_SUCCESS); +#if BTA_DYNAMIC_MEMORY + vSemaphoreDelete(deinit_semaphore); + deinit_semaphore = NULL; +#endif /* #if BTA_DYNAMIC_MEMORY */ } void btc_main_call_handler(btc_msg_t *msg)