readability fix: No assigns in if conditionals
Coccinelle-assisted:
@@
variable i;
expression E;
statement S1, S2;
@@
+ i = E;
if (
(
- (i = E)
+ i
!= ...
|
- (i = E)
+ i
== ...
|
- (i = E)
+ i
< ...
|
- (i = E)
+ i
> ...
|
- (i = E)
+ i
<= ...
|
- (i = E)
+ i
>= ...
|
- (i = E)
+ i
)
) S1 else S2
for file in $(find . -name "*.cc"); do
spatch --sp no-if-assigns.cocci --in-place $file
done
clang-format --style=file -i bta/**/*.cc
Test: mma -j37 and basic sanity testing on angler, sailfish
Change-Id: I41a2964afac347c24e13869b6c172e321e646091
diff --git a/bta/dm/bta_dm_act.cc b/bta/dm/bta_dm_act.cc
index 2e112fc..56cda90 100644
--- a/bta/dm/bta_dm_act.cc
+++ b/bta/dm/bta_dm_act.cc
@@ -1400,7 +1400,8 @@
data.inq_cmpl.num_resps = p_data->inq_cmpl.num;
bta_dm_search_cb.p_search_cback(BTA_DM_INQ_CMPL_EVT, &data);
- if ((bta_dm_search_cb.p_btm_inq_info = BTM_InqDbFirst()) != NULL) {
+ bta_dm_search_cb.p_btm_inq_info = BTM_InqDbFirst();
+ if (bta_dm_search_cb.p_btm_inq_info != NULL) {
/* start name and service discovery from the first device on inquiry result
*/
bta_dm_search_cb.name_discover_done = false;
@@ -2030,8 +2031,9 @@
APPL_TRACE_DEBUG("bta_dm_discover_next_device");
/* searching next device on inquiry result */
- if ((bta_dm_search_cb.p_btm_inq_info =
- BTM_InqDbNext(bta_dm_search_cb.p_btm_inq_info)) != NULL) {
+ bta_dm_search_cb.p_btm_inq_info =
+ BTM_InqDbNext(bta_dm_search_cb.p_btm_inq_info);
+ if (bta_dm_search_cb.p_btm_inq_info != NULL) {
bta_dm_search_cb.name_discover_done = false;
bta_dm_search_cb.peer_name[0] = 0;
bta_dm_discover_device(
@@ -2229,7 +2231,8 @@
/* application will parse EIR to find out remote device name */
result.inq_res.p_eir = p_eir;
- if ((p_inq_info = BTM_InqDbRead(p_inq->remote_bd_addr)) != NULL) {
+ p_inq_info = BTM_InqDbRead(p_inq->remote_bd_addr);
+ if (p_inq_info != NULL) {
/* initialize remt_name_not_required to false so that we get the name by
* default */
result.inq_res.remt_name_not_required = false;
@@ -3344,9 +3347,10 @@
char* p_temp;
/* If the name isn't already stored, try retrieving from BTM */
- if (*p_name == '\0')
- if ((p_temp = BTM_SecReadDevName(bta_dm_search_cb.peer_bdaddr)) != NULL)
- p_name = p_temp;
+ if (*p_name == '\0') {
+ p_temp = BTM_SecReadDevName(bta_dm_search_cb.peer_bdaddr);
+ if (p_temp != NULL) p_name = p_temp;
+ }
return p_name;
}
@@ -3917,7 +3921,8 @@
/* application will parse EIR to find out remote device name */
result.inq_res.p_eir = p_eir;
- if ((p_inq_info = BTM_InqDbRead(p_inq->remote_bd_addr)) != NULL) {
+ p_inq_info = BTM_InqDbRead(p_inq->remote_bd_addr);
+ if (p_inq_info != NULL) {
/* initialize remt_name_not_required to false so that we get the name by
* default */
result.inq_res.remt_name_not_required = false;
@@ -4320,9 +4325,9 @@
if (p_data->ble_observe.start) {
/*Save the callback to be called when a scan results are available */
bta_dm_search_cb.p_scan_cback = p_data->ble_observe.p_cback;
- if ((status = BTM_BleObserve(true, p_data->ble_observe.duration,
- bta_dm_observe_results_cb,
- bta_dm_observe_cmpl_cb)) != BTM_CMD_STARTED) {
+ status = BTM_BleObserve(true, p_data->ble_observe.duration,
+ bta_dm_observe_results_cb, bta_dm_observe_cmpl_cb);
+ if (status != BTM_CMD_STARTED) {
tBTA_DM_SEARCH data;
APPL_TRACE_WARNING(" %s BTM_BleObserve failed. status %d", __func__,
status);
@@ -4591,13 +4596,13 @@
APPL_TRACE_DEBUG("bta_dm_cfg_filter_cond");
BTM_BleGetVendorCapabilities(&cmn_vsc_cb);
if (0 != cmn_vsc_cb.filter_support) {
- if ((st = BTM_BleCfgFilterCondition(
- p_data->ble_cfg_filter_cond.action,
- p_data->ble_cfg_filter_cond.cond_type,
- (tBTM_BLE_PF_FILT_INDEX)p_data->ble_cfg_filter_cond.filt_index,
- (tBTM_BLE_PF_COND_PARAM*)p_data->ble_cfg_filter_cond.p_cond_param,
- bta_ble_scan_cfg_cmpl, p_data->ble_cfg_filter_cond.ref_value)) ==
- BTM_CMD_STARTED) {
+ st = BTM_BleCfgFilterCondition(
+ p_data->ble_cfg_filter_cond.action,
+ p_data->ble_cfg_filter_cond.cond_type,
+ (tBTM_BLE_PF_FILT_INDEX)p_data->ble_cfg_filter_cond.filt_index,
+ (tBTM_BLE_PF_COND_PARAM*)p_data->ble_cfg_filter_cond.p_cond_param,
+ bta_ble_scan_cfg_cmpl, p_data->ble_cfg_filter_cond.ref_value);
+ if (st == BTM_CMD_STARTED) {
bta_dm_cb.p_scan_filt_cfg_cback =
p_data->ble_cfg_filter_cond.p_filt_cfg_cback;
return;
@@ -4629,11 +4634,11 @@
BTM_BleGetVendorCapabilities(&cmn_vsc_cb);
if (0 != cmn_vsc_cb.filter_support) {
- if ((st = BTM_BleEnableDisableFilterFeature(
- p_data->ble_enable_scan_filt.action,
- p_data->ble_enable_scan_filt.p_filt_status_cback,
- (tBTM_BLE_REF_VALUE)p_data->ble_enable_scan_filt.ref_value)) ==
- BTM_CMD_STARTED)
+ st = BTM_BleEnableDisableFilterFeature(
+ p_data->ble_enable_scan_filt.action,
+ p_data->ble_enable_scan_filt.p_filt_status_cback,
+ (tBTM_BLE_REF_VALUE)p_data->ble_enable_scan_filt.ref_value);
+ if (st == BTM_CMD_STARTED)
bta_dm_cb.p_scan_filt_status_cback =
p_data->ble_enable_scan_filt.p_filt_status_cback;
return;
@@ -4663,14 +4668,15 @@
APPL_TRACE_DEBUG("bta_dm_scan_filter_param_setup");
BTM_BleGetVendorCapabilities(&cmn_vsc_cb);
if (0 != cmn_vsc_cb.filter_support) {
- if ((st = BTM_BleAdvFilterParamSetup(
- p_data->ble_scan_filt_param_setup.action,
- p_data->ble_scan_filt_param_setup.filt_index,
- (tBTM_BLE_PF_FILT_PARAMS*)&p_data->ble_scan_filt_param_setup
- .filt_params,
- p_data->ble_scan_filt_param_setup.p_target,
- p_data->ble_scan_filt_param_setup.p_filt_param_cback,
- p_data->ble_scan_filt_param_setup.ref_value)) == BTM_CMD_STARTED) {
+ st = BTM_BleAdvFilterParamSetup(
+ p_data->ble_scan_filt_param_setup.action,
+ p_data->ble_scan_filt_param_setup.filt_index,
+ (tBTM_BLE_PF_FILT_PARAMS*)&p_data->ble_scan_filt_param_setup
+ .filt_params,
+ p_data->ble_scan_filt_param_setup.p_target,
+ p_data->ble_scan_filt_param_setup.p_filt_param_cback,
+ p_data->ble_scan_filt_param_setup.ref_value);
+ if (st == BTM_CMD_STARTED) {
bta_dm_cb.p_scan_filt_param_cback =
p_data->ble_scan_filt_param_setup.p_filt_param_cback;
return;
diff --git a/bta/dm/bta_dm_main.cc b/bta/dm/bta_dm_main.cc
index b8c572b..3d25691 100644
--- a/bta/dm/bta_dm_main.cc
+++ b/bta/dm/bta_dm_main.cc
@@ -343,8 +343,8 @@
/* execute action functions */
for (i = 0; i < BTA_DM_SEARCH_ACTIONS; i++) {
- if ((action = state_table[p_msg->event & 0x00ff][i]) !=
- BTA_DM_SEARCH_IGNORE) {
+ action = state_table[p_msg->event & 0x00ff][i];
+ if (action != BTA_DM_SEARCH_IGNORE) {
(*bta_dm_search_action[action])((tBTA_DM_MSG*)p_msg);
} else {
break;
diff --git a/bta/dm/bta_dm_pm.cc b/bta/dm/bta_dm_pm.cc
index a857b97..e659796 100644
--- a/bta/dm/bta_dm_pm.cc
+++ b/bta/dm/bta_dm_pm.cc
@@ -578,8 +578,8 @@
for (i = 0; i < BTA_DM_NUM_PM_TIMER; i++) {
if (bta_dm_cb.pm_timer[i].in_use &&
bdcmp(bta_dm_cb.pm_timer[i].peer_bdaddr, peer_addr) == 0) {
- if ((timer_idx = bta_pm_action_to_timer_idx(pm_action)) !=
- BTA_DM_PM_MODE_TIMER_MAX) {
+ timer_idx = bta_pm_action_to_timer_idx(pm_action);
+ if (timer_idx != BTA_DM_PM_MODE_TIMER_MAX) {
remaining_ms =
alarm_get_remaining_ms(bta_dm_cb.pm_timer[i].timer[timer_idx]);
if (remaining_ms < timeout_ms) {
@@ -607,8 +607,8 @@
if (!timer_started) {
if (available_timer != BTA_DM_PM_MODE_TIMER_MAX) {
bdcpy(bta_dm_cb.pm_timer[available_timer].peer_bdaddr, peer_addr);
- if ((timer_idx = bta_pm_action_to_timer_idx(pm_action)) !=
- BTA_DM_PM_MODE_TIMER_MAX) {
+ timer_idx = bta_pm_action_to_timer_idx(pm_action);
+ if (timer_idx != BTA_DM_PM_MODE_TIMER_MAX) {
bta_dm_pm_start_timer(&bta_dm_cb.pm_timer[available_timer], timer_idx,
timeout_ms, p_srvcs->id, pm_action);
timer_started = true;