OSDN Git Service

cleanup: no assigns in conditionals
authorMarie Janssen <jamuraa@google.com>
Wed, 22 Feb 2017 16:35:29 +0000 (08:35 -0800)
committerMyles Watson <mylesgw@google.com>
Tue, 28 Feb 2017 21:21:10 +0000 (21:21 +0000)
Some assigns snuck into our conditionals, making the code harder to
read / follow.

Also remove some unnecessary null checks after osi_malloc that are
nearby.

Test: compiles, sanity check with device
Change-Id: Ia544da44060d9fc4363af9fbcb4112f3190f75ab

15 files changed:
bta/av/bta_av_aact.cc
bta/hd/bta_hd_act.cc
bta/hd/bta_hd_api.cc
bta/hd/bta_hd_main.cc
bta/hf_client/bta_hf_client_main.cc
embdrv/sbc/decoder/srce/bitalloc.c
stack/avct/avct_api.cc
stack/avdt/avdt_msg.cc
stack/btm/btm_sec.cc
stack/gatt/gatt_api.cc
stack/hid/hidd_api.cc
stack/l2cap/l2c_api.cc
stack/l2cap/l2c_main.cc
stack/rfcomm/port_api.cc
test/suite/rfcomm/rfcomm_unittest.cc

index e10bb67..defe9fb 100644 (file)
@@ -1356,7 +1356,8 @@ void bta_av_str_opened(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
     open.status = BTA_AV_SUCCESS;
     open.starting = bta_av_chk_start(p_scb);
     open.edr = 0;
-    if (NULL != (p = BTM_ReadRemoteFeatures(p_scb->peer_addr))) {
+    p = BTM_ReadRemoteFeatures(p_scb->peer_addr);
+    if (p != NULL) {
       if (HCI_EDR_ACL_2MPS_SUPPORTED(p)) open.edr |= BTA_AV_EDR_2MBPS;
       if (HCI_EDR_ACL_3MPS_SUPPORTED(p)) open.edr |= BTA_AV_EDR_3MBPS;
     }
index da36482..39ebd52 100644 (file)
@@ -91,7 +91,8 @@ void bta_hd_api_enable(tBTA_HD_DATA* p_data) {
   /* store parameters */
   bta_hd_cb.p_cback = p_data->api_enable.p_cback;
 
-  if ((ret = HID_DevRegister(bta_hd_cback)) == HID_SUCCESS) {
+  ret = HID_DevRegister(bta_hd_cback);
+  if (ret == HID_SUCCESS) {
     status = BTA_HD_OK;
   } else {
     APPL_TRACE_ERROR("%s: Failed to register HID device (%d)", __func__, ret);
@@ -126,7 +127,8 @@ void bta_hd_api_disable(void) {
   }
 
   /* Deregister with lower layer */
-  if ((ret = HID_DevDeregister()) == HID_SUCCESS) {
+  ret = HID_DevDeregister();
+  if (ret == HID_SUCCESS) {
     status = BTA_HD_OK;
   } else {
     APPL_TRACE_ERROR("%s: Failed to deregister HID device (%s)", __func__, ret);
index 7b402ea..773348d 100644 (file)
@@ -50,22 +50,19 @@ static const tBTA_SYS_REG bta_hd_reg = {bta_hd_hdl_event, BTA_HdDisable};
  *
  ******************************************************************************/
 void BTA_HdEnable(tBTA_HD_CBACK* p_cback) {
-  tBTA_HD_API_ENABLE* p_buf;
-
   APPL_TRACE_API("%s", __func__);
 
   bta_sys_register(BTA_ID_HD, &bta_hd_reg);
 
-  p_buf = (tBTA_HD_API_ENABLE*)osi_malloc((uint16_t)sizeof(tBTA_HD_API_ENABLE));
+  tBTA_HD_API_ENABLE* p_buf =
+      (tBTA_HD_API_ENABLE*)osi_malloc((uint16_t)sizeof(tBTA_HD_API_ENABLE));
 
-  if (p_buf != NULL) {
-    memset(p_buf, 0, sizeof(tBTA_HD_API_ENABLE));
+  memset(p_buf, 0, sizeof(tBTA_HD_API_ENABLE));
 
-    p_buf->hdr.event = BTA_HD_API_ENABLE_EVT;
-    p_buf->p_cback = p_cback;
+  p_buf->hdr.event = BTA_HD_API_ENABLE_EVT;
+  p_buf->p_cback = p_cback;
 
-    bta_sys_sendmsg(p_buf);
-  }
+  bta_sys_sendmsg(p_buf);
 }
 
 /*******************************************************************************
@@ -78,16 +75,13 @@ void BTA_HdEnable(tBTA_HD_CBACK* p_cback) {
  *
  ******************************************************************************/
 void BTA_HdDisable(void) {
-  BT_HDR* p_buf;
-
   APPL_TRACE_API("%s", __func__);
 
   bta_sys_deregister(BTA_ID_HD);
 
-  if ((p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR))) != NULL) {
-    p_buf->event = BTA_HD_API_DISABLE_EVT;
-    bta_sys_sendmsg(p_buf);
-  }
+  BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
+  p_buf->event = BTA_HD_API_DISABLE_EVT;
+  bta_sys_sendmsg(p_buf);
 }
 
 /*******************************************************************************
@@ -103,48 +97,45 @@ void BTA_HdDisable(void) {
 extern void BTA_HdRegisterApp(tBTA_HD_APP_INFO* p_app_info,
                               tBTA_HD_QOS_INFO* p_in_qos,
                               tBTA_HD_QOS_INFO* p_out_qos) {
-  tBTA_HD_REGISTER_APP* p_buf;
-
   APPL_TRACE_API("%s", __func__);
 
-  if ((p_buf = (tBTA_HD_REGISTER_APP*)osi_malloc(
-           sizeof(tBTA_HD_REGISTER_APP))) != NULL) {
-    p_buf->hdr.event = BTA_HD_API_REGISTER_APP_EVT;
-
-    if (p_app_info->p_name) {
-      strncpy(p_buf->name, p_app_info->p_name, BTA_HD_APP_NAME_LEN);
-      p_buf->name[BTA_HD_APP_NAME_LEN] = '\0';
-    } else {
-      p_buf->name[0] = '\0';
-    }
-
-    if (p_app_info->p_description) {
-      strncpy(p_buf->description, p_app_info->p_description,
-              BTA_HD_APP_DESCRIPTION_LEN);
-      p_buf->description[BTA_HD_APP_DESCRIPTION_LEN] = '\0';
-    } else {
-      p_buf->description[0] = '\0';
-    }
-
-    if (p_app_info->p_provider) {
-      strncpy(p_buf->provider, p_app_info->p_provider, BTA_HD_APP_PROVIDER_LEN);
-      p_buf->provider[BTA_HD_APP_PROVIDER_LEN] = '\0';
-    } else {
-      p_buf->provider[0] = '\0';
-    }
-
-    p_buf->subclass = p_app_info->subclass;
-
-    p_buf->d_len = p_app_info->descriptor.dl_len;
-    memcpy(p_buf->d_data, p_app_info->descriptor.dsc_list,
-           p_app_info->descriptor.dl_len);
-
-    // copy qos data as-is
-    memcpy(&p_buf->in_qos, p_in_qos, sizeof(tBTA_HD_QOS_INFO));
-    memcpy(&p_buf->out_qos, p_out_qos, sizeof(tBTA_HD_QOS_INFO));
-
-    bta_sys_sendmsg(p_buf);
+  tBTA_HD_REGISTER_APP* p_buf =
+      (tBTA_HD_REGISTER_APP*)osi_malloc(sizeof(tBTA_HD_REGISTER_APP));
+  p_buf->hdr.event = BTA_HD_API_REGISTER_APP_EVT;
+
+  if (p_app_info->p_name) {
+    strncpy(p_buf->name, p_app_info->p_name, BTA_HD_APP_NAME_LEN);
+    p_buf->name[BTA_HD_APP_NAME_LEN] = '\0';
+  } else {
+    p_buf->name[0] = '\0';
+  }
+
+  if (p_app_info->p_description) {
+    strncpy(p_buf->description, p_app_info->p_description,
+            BTA_HD_APP_DESCRIPTION_LEN);
+    p_buf->description[BTA_HD_APP_DESCRIPTION_LEN] = '\0';
+  } else {
+    p_buf->description[0] = '\0';
   }
+
+  if (p_app_info->p_provider) {
+    strncpy(p_buf->provider, p_app_info->p_provider, BTA_HD_APP_PROVIDER_LEN);
+    p_buf->provider[BTA_HD_APP_PROVIDER_LEN] = '\0';
+  } else {
+    p_buf->provider[0] = '\0';
+  }
+
+  p_buf->subclass = p_app_info->subclass;
+
+  p_buf->d_len = p_app_info->descriptor.dl_len;
+  memcpy(p_buf->d_data, p_app_info->descriptor.dsc_list,
+         p_app_info->descriptor.dl_len);
+
+  // copy qos data as-is
+  memcpy(&p_buf->in_qos, p_in_qos, sizeof(tBTA_HD_QOS_INFO));
+  memcpy(&p_buf->out_qos, p_out_qos, sizeof(tBTA_HD_QOS_INFO));
+
+  bta_sys_sendmsg(p_buf);
 }
 
 /*******************************************************************************
@@ -158,15 +149,12 @@ extern void BTA_HdRegisterApp(tBTA_HD_APP_INFO* p_app_info,
  *
  ******************************************************************************/
 extern void BTA_HdUnregisterApp(void) {
-  BT_HDR* p_buf;
-
   APPL_TRACE_API("%s", __func__);
 
-  if ((p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR))) != NULL) {
-    p_buf->event = BTA_HD_API_UNREGISTER_APP_EVT;
+  BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
+  p_buf->event = BTA_HD_API_UNREGISTER_APP_EVT;
 
-    bta_sys_sendmsg(p_buf);
-  }
+  bta_sys_sendmsg(p_buf);
 }
 
 /*******************************************************************************
@@ -179,8 +167,6 @@ extern void BTA_HdUnregisterApp(void) {
  *
  ******************************************************************************/
 extern void BTA_HdSendReport(tBTA_HD_REPORT* p_report) {
-  tBTA_HD_SEND_REPORT* p_buf;
-
   APPL_TRACE_VERBOSE("%s", __func__);
 
   if (p_report->len > BTA_HD_REPORT_LEN) {
@@ -191,18 +177,17 @@ extern void BTA_HdSendReport(tBTA_HD_REPORT* p_report) {
     return;
   }
 
-  if ((p_buf = (tBTA_HD_SEND_REPORT*)osi_malloc(sizeof(tBTA_HD_SEND_REPORT))) !=
-      NULL) {
-    p_buf->hdr.event = BTA_HD_API_SEND_REPORT_EVT;
+  tBTA_HD_SEND_REPORT* p_buf =
+      (tBTA_HD_SEND_REPORT*)osi_malloc(sizeof(tBTA_HD_SEND_REPORT));
+  p_buf->hdr.event = BTA_HD_API_SEND_REPORT_EVT;
 
-    p_buf->use_intr = p_report->use_intr;
-    p_buf->type = p_report->type;
-    p_buf->id = p_report->id;
-    p_buf->len = p_report->len;
-    memcpy(p_buf->data, p_report->p_data, p_report->len);
+  p_buf->use_intr = p_report->use_intr;
+  p_buf->type = p_report->type;
+  p_buf->id = p_report->id;
+  p_buf->len = p_report->len;
+  memcpy(p_buf->data, p_report->p_data, p_report->len);
 
-    bta_sys_sendmsg(p_buf);
-  }
+  bta_sys_sendmsg(p_buf);
 }
 
 /*******************************************************************************
@@ -215,15 +200,12 @@ extern void BTA_HdSendReport(tBTA_HD_REPORT* p_report) {
  *
  ******************************************************************************/
 extern void BTA_HdVirtualCableUnplug(void) {
-  BT_HDR* p_buf;
-
   APPL_TRACE_API("%s", __func__);
 
-  if ((p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR))) != NULL) {
-    p_buf->event = BTA_HD_API_VC_UNPLUG_EVT;
+  BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
+  p_buf->event = BTA_HD_API_VC_UNPLUG_EVT;
 
-    bta_sys_sendmsg(p_buf);
-  }
+  bta_sys_sendmsg(p_buf);
 }
 
 /*******************************************************************************
@@ -237,18 +219,15 @@ extern void BTA_HdVirtualCableUnplug(void) {
  *
  ******************************************************************************/
 extern void BTA_HdConnect(BD_ADDR addr) {
-  tBTA_HD_DEVICE_CTRL* p_buf;
-
   APPL_TRACE_API("%s", __func__);
 
-  if ((p_buf = (tBTA_HD_DEVICE_CTRL*)osi_malloc(sizeof(tBTA_HD_DEVICE_CTRL))) !=
-      NULL) {
-    p_buf->hdr.event = BTA_HD_API_CONNECT_EVT;
+  tBTA_HD_DEVICE_CTRL* p_buf =
+      (tBTA_HD_DEVICE_CTRL*)osi_malloc(sizeof(tBTA_HD_DEVICE_CTRL));
+  p_buf->hdr.event = BTA_HD_API_CONNECT_EVT;
 
-    memcpy(p_buf->addr, addr, sizeof(BD_ADDR));
+  memcpy(p_buf->addr, addr, sizeof(BD_ADDR));
 
-    bta_sys_sendmsg(p_buf);
-  }
+  bta_sys_sendmsg(p_buf);
 }
 
 /*******************************************************************************
@@ -261,15 +240,11 @@ extern void BTA_HdConnect(BD_ADDR addr) {
  *
  ******************************************************************************/
 extern void BTA_HdDisconnect(void) {
-  BT_HDR* p_buf;
-
   APPL_TRACE_API("%s", __func__);
+  BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
+  p_buf->event = BTA_HD_API_DISCONNECT_EVT;
 
-  if ((p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR))) != NULL) {
-    p_buf->event = BTA_HD_API_DISCONNECT_EVT;
-
-    bta_sys_sendmsg(p_buf);
-  }
+  bta_sys_sendmsg(p_buf);
 }
 
 /*******************************************************************************
@@ -282,18 +257,14 @@ extern void BTA_HdDisconnect(void) {
  *
  ******************************************************************************/
 extern void BTA_HdAddDevice(BD_ADDR addr) {
-  tBTA_HD_DEVICE_CTRL* p_buf;
-
   APPL_TRACE_API("%s", __func__);
+  tBTA_HD_DEVICE_CTRL* p_buf =
+      (tBTA_HD_DEVICE_CTRL*)osi_malloc(sizeof(tBTA_HD_DEVICE_CTRL));
+  p_buf->hdr.event = BTA_HD_API_ADD_DEVICE_EVT;
 
-  if ((p_buf = (tBTA_HD_DEVICE_CTRL*)osi_malloc(sizeof(tBTA_HD_DEVICE_CTRL))) !=
-      NULL) {
-    p_buf->hdr.event = BTA_HD_API_ADD_DEVICE_EVT;
+  memcpy(p_buf->addr, addr, sizeof(BD_ADDR));
 
-    memcpy(p_buf->addr, addr, sizeof(BD_ADDR));
-
-    bta_sys_sendmsg(p_buf);
-  }
+  bta_sys_sendmsg(p_buf);
 }
 
 /*******************************************************************************
@@ -306,18 +277,14 @@ extern void BTA_HdAddDevice(BD_ADDR addr) {
  *
  ******************************************************************************/
 extern void BTA_HdRemoveDevice(BD_ADDR addr) {
-  tBTA_HD_DEVICE_CTRL* p_buf;
-
   APPL_TRACE_API("%s", __func__);
+  tBTA_HD_DEVICE_CTRL* p_buf =
+      (tBTA_HD_DEVICE_CTRL*)osi_malloc(sizeof(tBTA_HD_DEVICE_CTRL));
+  p_buf->hdr.event = BTA_HD_API_REMOVE_DEVICE_EVT;
 
-  if ((p_buf = (tBTA_HD_DEVICE_CTRL*)osi_malloc(sizeof(tBTA_HD_DEVICE_CTRL))) !=
-      NULL) {
-    p_buf->hdr.event = BTA_HD_API_REMOVE_DEVICE_EVT;
-
-    memcpy(p_buf->addr, addr, sizeof(BD_ADDR));
+  memcpy(p_buf->addr, addr, sizeof(BD_ADDR));
 
-    bta_sys_sendmsg(p_buf);
-  }
+  bta_sys_sendmsg(p_buf);
 }
 
 /*******************************************************************************
@@ -330,17 +297,13 @@ extern void BTA_HdRemoveDevice(BD_ADDR addr) {
  *
  ******************************************************************************/
 extern void BTA_HdReportError(uint8_t error) {
-  tBTA_HD_REPORT_ERR* p_buf;
-
   APPL_TRACE_API("%s", __func__);
+  tBTA_HD_REPORT_ERR* p_buf =
+      (tBTA_HD_REPORT_ERR*)osi_malloc(sizeof(tBTA_HD_REPORT_ERR));
+  p_buf->hdr.event = BTA_HD_API_REPORT_ERROR_EVT;
+  p_buf->error = error;
 
-  if ((p_buf = (tBTA_HD_REPORT_ERR*)osi_malloc(sizeof(tBTA_HD_REPORT_ERR))) !=
-      NULL) {
-    p_buf->hdr.event = BTA_HD_API_REPORT_ERROR_EVT;
-    p_buf->error = error;
-
-    bta_sys_sendmsg(p_buf);
-  }
+  bta_sys_sendmsg(p_buf);
 }
 
 #endif /* BTA_HD_INCLUDED */
index 02577f6..dff5d9c 100644 (file)
@@ -253,7 +253,8 @@ void bta_hd_sm_execute(uint16_t event, tBTA_HD_DATA* p_data) {
 
   event &= 0xff;
 
-  if ((action = state_table[event][BTA_HD_ACTION]) < BTA_HD_IGNORE) {
+  action = state_table[event][BTA_HD_ACTION];
+  if (action < BTA_HD_IGNORE) {
     (*bta_hd_action[action])(p_data);
   }
 
index 86d8c2d..7c9293e 100644 (file)
@@ -581,8 +581,8 @@ tBTA_HF_CLIENT_CB* bta_hf_client_find_cb_by_sco_handle(uint16_t handle) {
  *
  ******************************************************************************/
 bool bta_hf_client_allocate_handle(const BD_ADDR bd_addr, uint16_t* p_handle) {
-  tBTA_HF_CLIENT_CB* existing_cb;
-  if ((existing_cb = bta_hf_client_find_cb_by_bda(bd_addr)) != NULL) {
+  tBTA_HF_CLIENT_CB* existing_cb = bta_hf_client_find_cb_by_bda(bd_addr);
+  if (existing_cb != NULL) {
     BTIF_TRACE_ERROR("%s: cannot allocate handle since BDADDR already exists",
                      __func__);
     return false;
index 6cb83ee..75e914a 100644 (file)
@@ -144,7 +144,8 @@ OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT* common, uint8_t* bitneeds,
       if (bits > maxBits) {
         maxBits = bits;
       }
-      if ((bitneeds[sb] = bits) > 1) {
+      bitneeds[sb] = bits;
+      if (bitneeds[sb] > 1) {
         bitcount += bits;
       }
       prefBits += 2 + bits;
@@ -169,7 +170,8 @@ OI_UINT computeBitneed(OI_CODEC_SBC_COMMON_CONTEXT* common, uint8_t* bitneeds,
         }
         bits += 5;
       }
-      if ((bitneeds[sb] = bits) > 1) {
+      bitneeds[sb] = bits;
+      if (bitneeds[sb] > 1) {
         bitcount += bits;
       }
     }
index 2910461..2a9a485 100644 (file)
@@ -320,9 +320,9 @@ uint16_t AVCT_RemoveBrowse(uint8_t handle) {
 uint16_t AVCT_GetBrowseMtu(uint8_t handle) {
   uint16_t peer_mtu = AVCT_MIN_BROWSE_MTU;
 
-  tAVCT_CCB* p_ccb;
+  tAVCT_CCB* p_ccb = avct_ccb_by_idx(handle);
 
-  if ((p_ccb = avct_ccb_by_idx(handle)) != NULL && p_ccb->p_bcb != NULL) {
+  if (p_ccb != NULL && p_ccb->p_bcb != NULL) {
     peer_mtu = p_ccb->p_bcb->peer_mtu;
   }
 
index 8d62a20..2595ab8 100644 (file)
@@ -1644,8 +1644,11 @@ void avdt_msg_ind(tAVDT_CCB* p_ccb, BT_HDR* p_buf) {
       /* Map seid to the scb and send it the event.  For cmd, seid has
       ** already been verified by parsing function.
       */
-      if (evt && (p_scb = avdt_scb_by_hdl(scb_hdl)) != NULL) {
-        avdt_scb_event(p_scb, evt, (tAVDT_SCB_EVT*)&msg);
+      if (evt) {
+        p_scb = avdt_scb_by_hdl(scb_hdl);
+        if (p_scb != NULL) {
+          avdt_scb_event(p_scb, evt, (tAVDT_SCB_EVT*)&msg);
+        }
       }
     }
   }
index b669ab5..3d7ac17 100644 (file)
@@ -1173,10 +1173,11 @@ tBTM_STATUS BTM_SecBondCancel(BD_ADDR bd_addr) {
   BTM_TRACE_API("BTM_SecBondCancel()  State: %s flags:0x%x",
                 btm_pair_state_descr(btm_cb.pairing_state),
                 btm_cb.pairing_flags);
-
-  if (((p_dev_rec = btm_find_dev(bd_addr)) == NULL) ||
-      (memcmp(btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN) != 0))
+  p_dev_rec = btm_find_dev(bd_addr);
+  if ((p_dev_rec == NULL) ||
+      (memcmp(btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN) != 0)) {
     return BTM_UNKNOWN_ADDR;
+  }
 
   if (btm_cb.pairing_flags & BTM_PAIR_FLAGS_LE_ACTIVE) {
     if (p_dev_rec->sec_state == BTM_SEC_STATE_AUTHENTICATING) {
@@ -1249,9 +1250,8 @@ tBTM_STATUS BTM_SecBondCancel(BD_ADDR bd_addr) {
  ******************************************************************************/
 tBTM_STATUS BTM_SecGetDeviceLinkKey(BD_ADDR bd_addr, LINK_KEY link_key) {
   tBTM_SEC_DEV_REC* p_dev_rec;
-
-  if (((p_dev_rec = btm_find_dev(bd_addr)) != NULL) &&
-      (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN)) {
+  p_dev_rec = btm_find_dev(bd_addr);
+  if ((p_dev_rec != NULL) && (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN)) {
     memcpy(link_key, p_dev_rec->link_key, LINK_KEY_LEN);
     return (BTM_SUCCESS);
   }
@@ -3523,8 +3523,8 @@ void btm_proc_sp_req_evt(tBTM_SP_EVT event, uint8_t* p) {
       (p_bda[4] << 8) + p_bda[5], event,
       btm_pair_state_descr(btm_cb.pairing_state));
 
-  if (((p_dev_rec = btm_find_dev(p_bda)) != NULL) &&
-      (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) &&
+  p_dev_rec = btm_find_dev(p_bda);
+  if ((p_dev_rec != NULL) && (btm_cb.pairing_state != BTM_PAIR_STATE_IDLE) &&
       (memcmp(btm_cb.pairing_bda, p_bda, BD_ADDR_LEN) == 0)) {
     memcpy(evt_data.cfm_req.bd_addr, p_dev_rec->bd_addr, BD_ADDR_LEN);
     memcpy(evt_data.cfm_req.dev_class, p_dev_rec->dev_class, DEV_CLASS_LEN);
@@ -3632,7 +3632,8 @@ void btm_proc_sp_req_evt(tBTM_SP_EVT event, uint8_t* p) {
     On Mobile platforms, if there's a security process happening,
     the host probably can not initiate another connection.
     BTW (PC) is another story.  */
-    if (NULL != (p_dev_rec = btm_find_dev(p_bda))) {
+    p_dev_rec = btm_find_dev(p_bda);
+    if (p_dev_rec != NULL) {
       btm_sec_disconnect(p_dev_rec->hci_handle, HCI_ERR_AUTH_FAILURE);
     }
   }
@@ -3770,8 +3771,8 @@ void btm_rem_oob_req(uint8_t* p) {
 
   BTM_TRACE_EVENT("btm_rem_oob_req() BDA: %02x:%02x:%02x:%02x:%02x:%02x",
                   p_bda[0], p_bda[1], p_bda[2], p_bda[3], p_bda[4], p_bda[5]);
-
-  if ((NULL != (p_dev_rec = btm_find_dev(p_bda))) && btm_cb.api.p_sp_callback) {
+  p_dev_rec = btm_find_dev(p_bda);
+  if ((p_dev_rec != NULL) && btm_cb.api.p_sp_callback) {
     memcpy(evt_data.bd_addr, p_dev_rec->bd_addr, BD_ADDR_LEN);
     memcpy(evt_data.dev_class, p_dev_rec->dev_class, DEV_CLASS_LEN);
     strlcpy((char*)evt_data.bd_name, (char*)p_dev_rec->sec_bd_name,
index f3b5a1f..49e8eef 100644 (file)
@@ -1220,10 +1220,13 @@ bool GATT_CancelConnect(tGATT_IF gatt_if, BD_ADDR bd_addr, bool is_direct) {
 
   GATT_TRACE_API("GATT_CancelConnect gatt_if=%d", gatt_if);
 
-  if ((gatt_if != 0) && ((p_reg = gatt_get_regcb(gatt_if)) == NULL)) {
-    GATT_TRACE_ERROR("GATT_CancelConnect - gatt_if =%d is not registered",
-                     gatt_if);
-    return (false);
+  if (gatt_if != 0) {
+    p_reg = gatt_get_regcb(gatt_if);
+    if (p_reg == NULL) {
+      GATT_TRACE_ERROR("GATT_CancelConnect - gatt_if =%d is not registered",
+                       gatt_if);
+      return (false);
+    }
   }
 
   if (is_direct) {
index bce5ef5..9879095 100644 (file)
@@ -92,9 +92,8 @@ tHID_STATUS HID_DevRegister(tHID_DEV_HOST_CALLBACK* host_cback) {
   if (host_cback == NULL) return HID_ERR_INVALID_PARAM;
 
   /* Register with L2CAP */
-  if ((st = hidd_conn_reg()) != HID_SUCCESS) {
-    return st;
-  }
+  st = hidd_conn_reg();
+  if (st != HID_SUCCESS) return st;
 
   hd_cb.callback = host_cback;
   hd_cb.reg_flag = TRUE;
index 7c0b7d8..2e208ed 100644 (file)
@@ -131,17 +131,20 @@ void L2CA_Deregister(uint16_t psm) {
     p_lcb = &l2cb.lcb_pool[0];
     for (ii = 0; ii < MAX_L2CAP_LINKS; ii++, p_lcb++) {
       if (p_lcb->in_use) {
-        if (((p_ccb = p_lcb->ccb_queue.p_first_ccb) == NULL) ||
-            (p_lcb->link_state == LST_DISCONNECTING))
+        p_ccb = p_lcb->ccb_queue.p_first_ccb;
+        if ((p_ccb == NULL) || (p_lcb->link_state == LST_DISCONNECTING)) {
           continue;
+        }
 
         if ((p_ccb->in_use) &&
             ((p_ccb->chnl_state == CST_W4_L2CAP_DISCONNECT_RSP) ||
-             (p_ccb->chnl_state == CST_W4_L2CA_DISCONNECT_RSP)))
+             (p_ccb->chnl_state == CST_W4_L2CA_DISCONNECT_RSP))) {
           continue;
+        }
 
-        if (p_ccb->p_rcb == p_rcb)
+        if (p_ccb->p_rcb == p_rcb) {
           l2c_csm_execute(p_ccb, L2CEVT_L2CA_DISCONNECT_REQ, NULL);
+        }
       }
     }
     l2cu_release_rcb(p_rcb);
@@ -253,10 +256,10 @@ uint16_t L2CA_ErtmConnectReq(uint16_t psm, BD_ADDR p_bd_addr,
   p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_BR_EDR);
   if (p_lcb == NULL) {
     /* No link. Get an LCB and start link establishment */
-    if (((p_lcb = l2cu_allocate_lcb(p_bd_addr, false, BT_TRANSPORT_BR_EDR)) ==
-         NULL)
-        /* currently use BR/EDR for ERTM mode l2cap connection */
-        || (l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR) == false)) {
+    p_lcb = l2cu_allocate_lcb(p_bd_addr, false, BT_TRANSPORT_BR_EDR);
+    /* currently use BR/EDR for ERTM mode l2cap connection */
+    if ((p_lcb == NULL) ||
+        (l2cu_create_conn(p_lcb, BT_TRANSPORT_BR_EDR) == false)) {
       L2CAP_TRACE_WARNING(
           "L2CAP - conn not started for PSM: 0x%04x  p_lcb: 0x%08x", psm,
           p_lcb);
@@ -1747,9 +1750,9 @@ uint16_t L2CA_SendFixedChnlData(uint16_t fixed_cid, BD_ADDR rem_bda,
   }
 
   // We need to have a link up
-  if ((p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, transport)) == NULL ||
-      /* if link is disconnecting, also report data sending failure */
-      p_lcb->link_state == LST_DISCONNECTING) {
+  p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, transport);
+  if (p_lcb == NULL || p_lcb->link_state == LST_DISCONNECTING) {
+    /* if link is disconnecting, also report data sending failure */
     L2CAP_TRACE_WARNING("L2CA_SendFixedChnlData(0x%04x) - no LCB", fixed_cid);
     osi_free(p_buf);
     return (L2CAP_DW_FAILED);
@@ -2134,11 +2137,12 @@ uint16_t L2CA_FlushChannel(uint16_t lcid, uint16_t num_to_flush) {
 
   p_ccb = l2cu_find_ccb_by_cid(NULL, lcid);
 
-  if (!p_ccb || ((p_lcb = p_ccb->p_lcb) == NULL)) {
+  if (!p_ccb || (p_ccb->p_lcb == NULL)) {
     L2CAP_TRACE_WARNING(
         "L2CA_FlushChannel()  abnormally returning 0  CID: 0x%04x", lcid);
     return (0);
   }
+  p_lcb = p_ccb->p_lcb;
 
   if (num_to_flush != L2CAP_FLUSH_CHANS_GET) {
     L2CAP_TRACE_API(
index d79fe1c..3adfab5 100644 (file)
@@ -290,7 +290,8 @@ static void process_l2cap_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {
   /* An L2CAP packet may contain multiple commands */
   while (true) {
     /* Smallest command is 4 bytes */
-    if ((p = p_next_cmd) > (p_pkt_end - 4)) break;
+    p = p_next_cmd;
+    if (p > (p_pkt_end - 4)) break;
 
     STREAM_TO_UINT8(cmd_code, p);
     STREAM_TO_UINT8(id, p);
@@ -303,7 +304,8 @@ static void process_l2cap_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {
     }
 
     /* Check command length does not exceed packet length */
-    if ((p_next_cmd = p + cmd_len) > p_pkt_end) {
+    p_next_cmd = p + cmd_len;
+    if (p_next_cmd > p_pkt_end) {
       L2CAP_TRACE_WARNING("Command len bad  pkt_len: %d  cmd_len: %d  code: %d",
                           pkt_len, cmd_len, cmd_code);
       break;
@@ -342,8 +344,8 @@ static void process_l2cap_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {
               rcid);
 
           /* Remote CID invalid. Treat as a disconnect */
-          if (((p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid)) != NULL) &&
-              (p_ccb->remote_cid == rcid)) {
+          p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid);
+          if ((p_ccb != NULL) && (p_ccb->remote_cid == rcid)) {
             /* Fake link disconnect - no reply is generated */
             l2c_csm_execute(p_ccb, L2CEVT_LP_DISCONNECT_IND, NULL);
           }
index 196fb42..de4cf0b 100644 (file)
@@ -145,16 +145,19 @@ int RFCOMM_CreateConnection(uint16_t uuid, uint8_t scn, bool is_server,
 
   /* For the server side always allocate a new port.  On the client side */
   /* do not allow the same (dlci, bd_addr) to be opened twice by application */
-  if (!is_server && ((p_port = port_find_port(dlci, bd_addr)) != NULL)) {
-    /* if existing port is also a client port */
-    if (p_port->is_server == false) {
-      RFCOMM_TRACE_ERROR(
-          "RFCOMM_CreateConnection - already opened state:%d, RFC state:%d, "
-          "MCB state:%d",
-          p_port->state, p_port->rfc.state,
-          p_port->rfc.p_mcb ? p_port->rfc.p_mcb->state : 0);
-      *p_handle = p_port->inx;
-      return (PORT_ALREADY_OPENED);
+  if (!is_server) {
+    p_port = port_find_port(dlci, bd_addr);
+    if (p_port != NULL) {
+      /* if existing port is also a client port */
+      if (p_port->is_server == false) {
+        RFCOMM_TRACE_ERROR(
+            "RFCOMM_CreateConnection - already opened state:%d, RFC state:%d, "
+            "MCB state:%d",
+            p_port->state, p_port->rfc.state,
+            p_port->rfc.p_mcb ? p_port->rfc.p_mcb->state : 0);
+        *p_handle = p_port->inx;
+        return (PORT_ALREADY_OPENED);
+      }
     }
   }
 
@@ -1439,8 +1442,8 @@ int PORT_WriteDataCO(uint16_t handle, int* p_len) {
   /* data fits into the end of the queue */
   mutex_global_lock();
 
-  if (((p_buf = (BT_HDR*)fixed_queue_try_peek_last(p_port->tx.queue)) !=
-       NULL) &&
+  p_buf = (BT_HDR*)fixed_queue_try_peek_last(p_port->tx.queue);
+  if ((p_buf != NULL) &&
       (((int)p_buf->len + available) <= (int)p_port->peer_mtu) &&
       (((int)p_buf->len + available) <= (int)length)) {
     // if(recv(fd, (uint8_t *)(p_buf + 1) + p_buf->offset + p_buf->len,
@@ -1586,9 +1589,8 @@ int PORT_WriteData(uint16_t handle, const char* p_data, uint16_t max_len,
   /* data fits into the end of the queue */
   mutex_global_lock();
 
-  if (((p_buf = (BT_HDR*)fixed_queue_try_peek_last(p_port->tx.queue)) !=
-       NULL) &&
-      ((p_buf->len + max_len) <= p_port->peer_mtu) &&
+  p_buf = (BT_HDR*)fixed_queue_try_peek_last(p_port->tx.queue);
+  if ((p_buf != NULL) && ((p_buf->len + max_len) <= p_port->peer_mtu) &&
       ((p_buf->len + max_len) <= length)) {
     memcpy((uint8_t*)(p_buf + 1) + p_buf->offset + p_buf->len, p_data, max_len);
     p_port->tx.queue_size += max_len;
index 7655a8f..b81f781 100644 (file)
@@ -86,13 +86,15 @@ TEST_F(RFCommTest, RfcommRepeatedConnectPairedDevice) {
 
     int channel;
     sock_connect_signal_t signal;
-    if ((len = read(fd, &channel, sizeof(channel))) != sizeof(channel)) {
+    len = read(fd, &channel, sizeof(channel));
+    if (len != sizeof(channel)) {
       ADD_FAILURE() << "Channel not read from RFCOMM socket. Bytes read: "
                     << len << ", Sizeof channel: " << sizeof(channel);
       channel_fail++;
     }
 
-    if ((len = read(fd, &signal, sizeof(signal))) != sizeof(signal)) {
+    len = read(fd, &signal, sizeof(signal));
+    if (len != sizeof(signal)) {
       ADD_FAILURE()
           << "Connection signal not read from RFCOMM socket. Bytes read: "
           << len;
@@ -105,15 +107,15 @@ TEST_F(RFCommTest, RfcommRepeatedConnectPairedDevice) {
     EXPECT_TRUE(channel == signal.channel)
         << "Inconsistent channels returned: " << channel << " and "
         << signal.channel;
-
-    if ((len = write(fd, HANDSHAKE_COMMAND, sizeof(HANDSHAKE_COMMAND))) !=
-        sizeof(HANDSHAKE_COMMAND)) {
+    len = write(fd, HANDSHAKE_COMMAND, sizeof(HANDSHAKE_COMMAND));
+    if (len != sizeof(HANDSHAKE_COMMAND)) {
       ADD_FAILURE() << "Unable to send HFP handshake. Bytes written: " << len;
       handshake_fail++;
     }
 
     char response[1024];
-    if ((len = read(fd, response, sizeof(response))) <= 0) {
+    len = read(fd, response, sizeof(response));
+    if (len <= 0) {
       ADD_FAILURE() << "Read " << len << " bytes";
       read_fail++;
     }