From 3c088db87328bdb138ebc93df558e22226597a07 Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Thu, 16 Nov 2023 20:09:29 +0800 Subject: [PATCH] fix(bt/bluedroid): Added dynamic memory allocation for HFP control blocks --- .../bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 8ababa1c6f..be2866e81c 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 @@ -66,7 +66,7 @@ static UINT16 btc_max_hf_clients = BTC_HF_NUM_CB; #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; +static hf_local_param_t *hf_local_param = NULL; #endif #if (BTM_WBS_INCLUDED == TRUE) @@ -315,6 +315,19 @@ bt_status_t btc_hf_init(void) int idx = 0; BTC_TRACE_DEBUG("%s - max_hf_clients=%d", __func__, btc_max_hf_clients); + +#if HFP_DYNAMIC_MEMORY == TRUE + if (hf_local_param != NULL) { + return BT_STATUS_FAIL; + } + + if ((hf_local_param = (hf_local_param_t *)osi_malloc(BTC_HF_NUM_CB * sizeof(hf_local_param_t))) == NULL) { + APPL_TRACE_ERROR("%s malloc failed!", __func__); + return BT_STATUS_NOMEM; + } + memset((void *)hf_local_param, 0, BTC_HF_NUM_CB * sizeof(hf_local_param_t)); +#endif + /* 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) * othwerwise only HSP is enabled (tablet)*/