fix(bt/bluedroid): cleaned the code according to the tool cppcheck

This commit is contained in:
Jin Cheng
2025-12-19 17:02:01 +08:00
parent caf1c72daf
commit 0fb6be8d87
24 changed files with 67 additions and 74 deletions
@@ -749,14 +749,14 @@ UINT8 avdt_scb_verify(tAVDT_CCB *p_ccb, UINT8 state, UINT8 *p_seid, UINT16 num_s
switch (state) {
case AVDT_VERIFY_OPEN:
case AVDT_VERIFY_START:
if (p_scb->state != AVDT_SCB_OPEN_ST && p_scb->state != AVDT_SCB_STREAM_ST) {
if (p_scb && p_scb->state != AVDT_SCB_OPEN_ST && p_scb->state != AVDT_SCB_STREAM_ST) {
*p_err_code = AVDT_ERR_BAD_STATE;
}
break;
case AVDT_VERIFY_SUSPEND:
case AVDT_VERIFY_STREAMING:
if (p_scb->state != AVDT_SCB_STREAM_ST) {
if (p_scb && p_scb->state != AVDT_SCB_STREAM_ST) {
*p_err_code = AVDT_ERR_BAD_STATE;
}
break;
@@ -2389,7 +2389,7 @@ BOOLEAN BTM_BleVerifySignature (BD_ADDR bd_addr, UINT8 *p_orig, UINT16 len, UINT
tBTM_SEC_DEV_REC *p_rec = btm_find_dev (bd_addr);
UINT8 p_mac[BTM_CMAC_TLEN_SIZE];
if (p_rec == NULL || (p_rec && !(p_rec->ble.key_type & BTM_LE_KEY_PCSRK))) {
if (p_rec == NULL || !(p_rec->ble.key_type & BTM_LE_KEY_PCSRK)) {
BTM_TRACE_ERROR("can not verify signature for unknown device");
} else if (counter < p_rec->ble.keys.counter) {
BTM_TRACE_ERROR("signature received with out dated sign counter");
@@ -429,8 +429,7 @@ BOOLEAN btm_ble_dealloc_addr_filter_counter(tBLE_BD_ADDR *p_bd_addr, UINT8 filte
for (i = 0; i < cmn_ble_adv_vsc_cb.max_filter; i ++, p_addr_filter ++) {
if ((p_addr_filter->in_use) && (NULL == p_bd_addr ||
(NULL != p_bd_addr &&
memcmp(p_bd_addr->bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0))) {
(memcmp(p_bd_addr->bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0)) {
found = TRUE;
memset(p_addr_filter, 0, sizeof(tBTM_BLE_PF_COUNT));
@@ -915,7 +914,7 @@ tBTM_STATUS btm_ble_clear_scan_pf_filter(tBTM_BLE_SCAN_COND_OP action,
if (NULL == p_bda_filter ||
/* not a generic filter */
(p_target != NULL && p_bda_filter)) {
(p_target != NULL)) {
BTM_TRACE_ERROR("Error: Can not clear filter, No PF filter has been configured!");
return st;
}
@@ -3745,7 +3745,7 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt
3. For same address and scan response, do nothing
*/
int same_addr = memcmp(bda, p_le_inq_cb->adv_addr, BD_ADDR_LEN);
if (same_addr != 0 || (same_addr == 0 && evt_type != BTM_BLE_SCAN_RSP_EVT)) {
if (same_addr != 0 || (evt_type != BTM_BLE_SCAN_RSP_EVT)) {
btm_ble_process_last_adv_pkt();
}
@@ -3796,8 +3796,7 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt
/* new device */
if (p_i == NULL ||
/* assume a DUMO device, BR/EDR inquiry is always active */
(p_i &&
(p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE &&
((p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE &&
p_i->scan_rsp)) {
BTM_TRACE_WARNING("INQ RES: Extra Response Received...cancelling inquiry..");
@@ -1860,7 +1860,7 @@ void btm_process_inq_results (UINT8 *p, UINT8 inq_res_mode)
/* new device response */
&& ( p_i == NULL ||
/* existing device with BR/EDR info */
(p_i && (p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BREDR) != 0)
((p_i->inq_info.results.device_type & BT_DEVICE_TYPE_BREDR) != 0)
)
#endif
@@ -866,9 +866,7 @@ void btm_pm_proc_ssr_evt (UINT8 *p, UINT16 evt_len)
/* notify registered parties */
for (xx = 0; xx < BTM_MAX_PM_RECORDS; xx++) {
if (btm_cb.pm_reg_db[xx].mask & BTM_PM_REG_NOTIF) {
if ( p_acl) {
(*btm_cb.pm_reg_db[xx].cback)( p_acl->remote_addr, BTM_PM_STS_SSR, use_ssr, status);
}
(*btm_cb.pm_reg_db[xx].cback)( p_acl->remote_addr, BTM_PM_STS_SSR, use_ssr, status);
}
}
}
@@ -916,7 +916,7 @@ static void l2c_csm_open (tL2C_CCB *p_ccb, UINT16 event, void *p_data)
case L2CEVT_LP_QOS_VIOLATION_IND: /* QOS violation */
/* Tell upper layer. If service guaranteed, then clear the channel */
if (p_ccb->p_rcb->api.pL2CA_QoSViolationInd_Cb) {
if (p_ccb->p_rcb && p_ccb->p_rcb->api.pL2CA_QoSViolationInd_Cb) {
(*p_ccb->p_rcb->api.pL2CA_QoSViolationInd_Cb)(p_ccb->p_lcb->remote_bd_addr);
}
break;
@@ -181,7 +181,7 @@ int RFCOMM_CreateConnection (UINT16 uuid, UINT8 scn, BOOLEAN is_server,
/* If the MTU is not specified (0), keep MTU decision until the
* PN frame has to be send
* at that time connection should be established and we
* will know for sure our prefered MTU
* will know for sure our preferred MTU
*/
rfcomm_mtu = L2CAP_MTU_SIZE - RFCOMM_DATA_OVERHEAD;
@@ -298,12 +298,12 @@ int RFCOMM_RemoveServer (UINT16 handle)
**
** Description This function is called to provide an address of the
** function which will be called when one of the events
** specified in the mask occures.
** specified in the mask occurs.
**
** Parameters: handle - Handle returned in the RFCOMM_CreateConnection
** p_callback - address of the callback function which should
** be called from the RFCOMM when an event
** specified in the mask occures.
** specified in the mask occurs.
**
**
*******************************************************************************/
@@ -537,8 +537,7 @@ BOOLEAN PORT_IsOpening (BD_ADDR bd_addr)
}
}
if ((!found_port) ||
(found_port && (p_port->rfc.state < RFC_STATE_OPENED))) {
if ((!found_port) || (p_port->rfc.state < RFC_STATE_OPENED)) {
/* Port is not established yet. */
memcpy (bd_addr, rfc_cb.port.rfc_mcb[xx].bd_addr, BD_ADDR_LEN);
return TRUE;
@@ -641,7 +640,7 @@ int PORT_GetRxQueueCnt (UINT16 handle, UINT16 *p_rx_queue_count)
** Function PORT_GetState
**
** Description This function is called to fill tPORT_STATE structure
** with the curremt control settings for the port
** with the current control settings for the port
**
** Parameters: handle - Handle returned in the RFCOMM_CreateConnection
** p_settings - Pointer to a tPORT_STATE structure in which
@@ -1009,15 +1008,15 @@ int PORT_GetModemStatus (UINT16 handle, UINT8 *p_signal)
**
** Function PORT_ClearError
**
** Description This function retreives information about a communications
** Description This function retrieves information about a communications
** error and reports current status of a connection. The
** function should be called when an error occures to clear
** function should be called when an error occurs to clear
** the connection error flag and to enable additional read
** and write operations.
**
** Parameters: handle - Handle returned in the RFCOMM_CreateConnection
** p_errors - pointer of the variable to receive error codes
** p_status - pointer to the tPORT_STATUS structur to receive
** p_status - pointer to the tPORT_STATUS structure to receive
** connection status
**
*******************************************************************************/
@@ -1090,7 +1089,7 @@ int PORT_SendError (UINT16 handle, UINT8 errors)
** Description This function reports current status of a connection.
**
** Parameters: handle - Handle returned in the RFCOMM_CreateConnection
** p_status - pointer to the tPORT_STATUS structur to receive
** p_status - pointer to the tPORT_STATUS structure to receive
** connection status
**
*******************************************************************************/
@@ -1700,7 +1699,7 @@ int PORT_WriteData (UINT16 handle, char *p_data, UINT16 max_len, UINT16 *p_len)
rc = port_write (p_port, p_buf);
/* If queue went below the threashold need to send flow control */
/* If queue went below the threshold need to send flow control */
event |= port_flow_control_user (p_port);
if (rc == PORT_SUCCESS) {
@@ -865,7 +865,7 @@ void smp_br_process_pairing_command(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
SMP_TRACE_DEBUG("%s", __func__);
/* rejecting BR pairing request over non-SC BR link */
if (!p_dev_rec->new_encryption_key_is_p256 && p_cb->role == HCI_ROLE_SLAVE) {
if (p_dev_rec && !p_dev_rec->new_encryption_key_is_p256 && p_cb->role == HCI_ROLE_SLAVE) {
reason = SMP_XTRANS_DERIVE_NOT_ALLOW;
smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &reason);
return;
@@ -2231,7 +2231,7 @@ void smp_process_new_nonce(tSMP_CB *p_cb)
static void smp_rand_back(tBTM_RAND_ENC *p)
{
tSMP_CB *p_cb = &smp_cb;
UINT8 *pp = p->param_buf;
UINT8 *pp = NULL;
UINT8 failure = SMP_PAIR_FAIL_UNKNOWN;
UINT8 state = p_cb->rand_enc_proc_state & ~0x80;
@@ -2249,11 +2249,13 @@ static void smp_rand_back(tBTM_RAND_ENC *p)
break;
case SMP_GEN_DIV_LTK:
pp = p->param_buf;
STREAM_TO_UINT16(p_cb->div, pp);
smp_generate_ltk_cont(p_cb, NULL);
break;
case SMP_GEN_DIV_CSRK:
pp = p->param_buf;
STREAM_TO_UINT16(p_cb->div, pp);
smp_compute_csrk(p_cb, NULL);
break;