From 5b5a36a7b2fc98188655651a292363cd774fa96d Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Fri, 9 Apr 2021 15:59:29 +0800 Subject: [PATCH 1/2] fix ag use dynamic memory error --- .../bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c | 16 ++++++++++++++++ .../btc/profile/std/include/btc_hf_ag.h | 5 ----- components/bt/host/bluedroid/main/bte_init.c | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c index 32f9c23836..1eadb3924b 100644 --- a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c +++ b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c @@ -53,7 +53,11 @@ /* Max HF Clients Supported From App */ static UINT16 btc_max_hf_clients = 1; /* HF Param Definition */ +#if HFP_DYNAMIC_MEMORY == FALSE static hf_local_param_t hf_local_param[BTC_HF_NUM_CB]; +#else +static hf_local_param_t *hf_local_param; +#endif #if (BTM_WBS_INCLUDED == TRUE) #ifndef BTC_HF_FEATURES @@ -296,6 +300,11 @@ bt_status_t btc_hf_execute_service(BOOLEAN b_enable) ************************************************************************************/ bt_status_t btc_hf_init(bt_bdaddr_t *bd_addr) { +#if HFP_DYNAMIC_MEMORY == TRUE + if ((hf_local_param = (hf_local_param_t *)osi_malloc(sizeof(hf_local_param_t) * BTC_HF_NUM_CB)) == NULL) { + return BT_STATUS_FAIL; + } +#endif int idx = btc_hf_idx_by_bdaddr(bd_addr); BTC_TRACE_DEBUG("%s - max_hf_clients=%d", __func__, btc_max_hf_clients); /* Invoke the enable service API to the core to set the appropriate service_id @@ -325,7 +334,14 @@ void btc_hf_deinit(bt_bdaddr_t *bd_addr) int idx = btc_hf_idx_by_bdaddr(bd_addr); BTC_TRACE_EVENT("%s", __FUNCTION__); btc_dm_disable_service(BTA_HFP_SERVICE_ID); +#if HFP_DYNAMIC_MEMORY == TRUE + if (hf_local_param) { + osi_free(hf_local_param); + hf_local_param = NULL; + } +#else hf_local_param[idx].btc_hf_cb.initialized = false; +#endif } static bt_status_t connect_init(bt_bdaddr_t *bd_addr, uint16_t uuid) diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_ag.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_ag.h index 5d1edbb8d4..38530e7039 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_ag.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_ag.h @@ -206,11 +206,6 @@ typedef union /* APP ID definition*/ #define BTC_HF_ID_1 0 -#if HFP_DYNAMIC_MEMORY == TRUE -extern hf_local_param_t *hf_local_param_ptr; -#define hf_local_param (*hf_local_param_ptr) -#endif - /* BTC-AG control block to map bdaddr to BTA handle */ typedef struct { diff --git a/components/bt/host/bluedroid/main/bte_init.c b/components/bt/host/bluedroid/main/bte_init.c index 7f3723ae55..d2373d10eb 100644 --- a/components/bt/host/bluedroid/main/bte_init.c +++ b/components/bt/host/bluedroid/main/bte_init.c @@ -93,6 +93,10 @@ #include "bta_hf_client_int.h" #endif +#if BTA_AG_INCLUDED == TRUE +#include "bta_ag_int.h" +#endif + #if BTA_SDP_INCLUDED == TRUE #include "bta_sdp_int.h" #endif @@ -216,6 +220,12 @@ void BTE_DeinitStack(void) osi_free(bta_hf_client_cb_ptr); bta_hf_client_cb_ptr = NULL; } +#endif +#if (defined BTA_AG_INCLUDED && BTA_AG_INCLUDED == TRUE) + if (bta_ag_cb_ptr){ + osi_free(bta_ag_cb_ptr); + bta_ag_cb_ptr = NULL; + } #endif if (bta_dm_conn_srvcs_ptr){ osi_free(bta_dm_conn_srvcs_ptr); @@ -374,6 +384,12 @@ bt_status_t BTE_InitStack(void) } memset((void *)bta_hf_client_cb_ptr, 0, sizeof(tBTA_HF_CLIENT_CB)); #endif +#if (defined BTA_AG_INCLUDED && BTA_AG_INCLUDED == TRUE) + if ((bta_ag_cb_ptr = (tBTA_AG_CB *)osi_malloc(sizeof(tBTA_AG_CB))) == NULL) { + goto error_exit; + } + memset((void *)bta_ag_cb_ptr, 0, sizeof(tBTA_AG_CB)); +#endif #if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE) if ((bta_jv_cb_ptr = (tBTA_JV_CB *)osi_malloc(sizeof(tBTA_JV_CB))) == NULL) { goto error_exit; From 7c53e88b0586e36b15a7fe5c379d04bf1ab978f6 Mon Sep 17 00:00:00 2001 From: xiongweichao Date: Mon, 10 May 2021 11:11:02 +0800 Subject: [PATCH 2/2] Remove btc_hf_idx_by_bdaddr in both btc_hf_init and btc_hf_deinit functions --- .../host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c index 1eadb3924b..83f3b6691d 100644 --- a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c +++ b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c @@ -300,12 +300,15 @@ bt_status_t btc_hf_execute_service(BOOLEAN b_enable) ************************************************************************************/ bt_status_t btc_hf_init(bt_bdaddr_t *bd_addr) { + int idx = 0; + UNUSED(bd_addr); + #if HFP_DYNAMIC_MEMORY == TRUE if ((hf_local_param = (hf_local_param_t *)osi_malloc(sizeof(hf_local_param_t) * BTC_HF_NUM_CB)) == NULL) { return BT_STATUS_FAIL; } #endif - int idx = btc_hf_idx_by_bdaddr(bd_addr); + BTC_TRACE_DEBUG("%s - max_hf_clients=%d", __func__, btc_max_hf_clients); /* Invoke the enable service API to the core to set the appropriate service_id * Internally, the HSP_SERVICE_ID shall also be enabled if HFP is enabled (phone) @@ -331,7 +334,8 @@ bt_status_t btc_hf_init(bt_bdaddr_t *bd_addr) void btc_hf_deinit(bt_bdaddr_t *bd_addr) { - int idx = btc_hf_idx_by_bdaddr(bd_addr); + UNUSED(bd_addr); + BTC_TRACE_EVENT("%s", __FUNCTION__); btc_dm_disable_service(BTA_HFP_SERVICE_ID); #if HFP_DYNAMIC_MEMORY == TRUE @@ -340,7 +344,7 @@ void btc_hf_deinit(bt_bdaddr_t *bd_addr) hf_local_param = NULL; } #else - hf_local_param[idx].btc_hf_cb.initialized = false; + hf_local_param[0].btc_hf_cb.initialized = false; #endif }