staging: rtl8723bs: remove ternary operators in assignmet statments
PATCH v2 1/1 staging: rtl8723bs: remove ternary operators in assignmet statments
Remove unnecessary ternary operators in assignments statments.
This patch is with the help of following Coccinelle script:
@@
expression a, b, c;
binary operator op = {==, !=, <=, >=, <, >, &&, ||}; @@
c =
- (a op b) ? true : false
+ a op b
---
Changes in v2:
- removed error in Coccinelle script
- corrected checkpatch.pl warnings for the patch
drivers/staging/rtl8723bs/core/rtw_ioctl_set.c | 2 +- drivers/staging/rtl8723bs/core/rtw_pwrctrl.c | 5 +++-- drivers/staging/rtl8723bs/core/rtw_sta_mgt.c | 2 +- drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 2 +- drivers/staging/rtl8723bs/hal/hal_btcoex.c | 4 ++-- drivers/staging/rtl8723bs/hal/hal_com.c | 6 +++--- drivers/staging/rtl8723bs/hal/odm_CfoTracking.c | 2 +- drivers/staging/rtl8723bs/hal/odm_HWConfig.c | 2 +- drivers/staging/rtl8723bs/hal/sdio_halinit.c | 4 ++-- 9 files changed, 15 insertions(+), 14 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ioctl_set.c +1 -1
@@ -597,7 +597,7 @@ u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep)u8 ret = _SUCCESS; bdefaultkey = (wep->KeyIndex &0x40000000 ) >0 ? false : true;/* for ??? */ - btransmitkey = (wep->KeyIndex &0x80000000 ) >0 ? true : false;/* for ??? */ + btransmitkey = (wep->KeyIndex &0x80000000 ) >0 ;/* for ??? */ keyid = wep->KeyIndex &0x3fffffff ;if (keyid >=4 ) {
drivers/staging/rtl8723bs/core/rtw_pwrctrl.c +3 -2
@@ -1154,7 +1154,7 @@ void rtw_init_pwrctrl_priv(struct adapter *padapter) pwrctrlpriv->LpsIdleCount =0 ; pwrctrlpriv->power_mgnt = padapter->registrypriv.power_mgnt;/* PS_MODE_MIN; */ - pwrctrlpriv->bLeisurePs = (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt)?true:false; + pwrctrlpriv->bLeisurePs = pwrctrlpriv->power_mgnt !=PS_MODE_ACTIVE ; pwrctrlpriv->bFwCurrentInPSMode = false;
@@ -1325,7 +1325,8 @@ int rtw_pm_set_lps(struct adapter *padapter, u8 mode) pwrctrlpriv->LpsIdleCount =2 ; pwrctrlpriv->power_mgnt = mode; - pwrctrlpriv->bLeisurePs = (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt)?true:false; + pwrctrlpriv->bLeisurePs = + pwrctrlpriv->power_mgnt !=PS_MODE_ACTIVE ; } }else ret = -EINVAL ;
drivers/staging/rtl8723bs/core/rtw_sta_mgt.c +1 -1
@@ -633,7 +633,7 @@ u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr) res = (match == true) ? false:true; else if (pacl_list->mode == 2)/* deny unless in accept list */ - res = (match == true) ? true:false; + res = match == true; else res = true;
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +1 -1
@@ -1946,7 +1946,7 @@ void process_addba_req(struct adapter *padapter, u8 *paddba_req, u8 *addr) preorder_ctrl->indicate_seq =0xffff ;#endif - preorder_ctrl->enable = (pmlmeinfo->bAcceptAddbaReq == true) ? true : false; + preorder_ctrl->enable = pmlmeinfo->bAcceptAddbaReq == true; } }
drivers/staging/rtl8723bs/hal/hal_btcoex.c +2 -2
@@ -463,7 +463,7 @@ static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)break ;case BTC_GET_BL_WIFI_UNDER_5G : - *pu8 = (pHalData->CurrentBandType ==1 ) ? true : false; + *pu8 = pHalData->CurrentBandType ==1 ;break ;case BTC_GET_BL_WIFI_AP_MODE_ENABLE :
@@ -1417,7 +1417,7 @@ u8 hal_btcoex_Initialize(struct adapter *padapter)memset (&GLBtCoexist,0 ,sizeof (GLBtCoexist)); ret1 =EXhalbtcoutsrc_InitlizeVariables ((void *)padapter); - ret2 = (ret1 == true) ? true : false; + ret2 = ret1 == true;return ret2; }
drivers/staging/rtl8723bs/hal/hal_com.c +3 -3
@@ -1623,7 +1623,7 @@ void rtw_get_raw_rssi_info(void *sel, struct adapter *padapter) psample_pkt_rssi->pwdball, psample_pkt_rssi->pwr_all ); - isCCKrate = (psample_pkt_rssi->data_rate <=DESC_RATE11M ) ? true : false; + isCCKrate = psample_pkt_rssi->data_rate <=DESC_RATE11M ;if (isCCKrate) psample_pkt_rssi->mimo_singal_strength[0 ] = psample_pkt_rssi->pwdball;
@@ -1656,7 +1656,7 @@ void rtw_dump_raw_rssi_info(struct adapter *padapter)DBG_871X ("RxRate = %s, PWDBALL = %d(%%), rx_pwr_all = %d(dBm)\n" ,HDATA_RATE (psample_pkt_rssi->data_rate), psample_pkt_rssi->pwdball, psample_pkt_rssi->pwr_all); - isCCKrate = (psample_pkt_rssi->data_rate <=DESC_RATE11M ) ? true : false; + isCCKrate = psample_pkt_rssi->data_rate <=DESC_RATE11M ;if (isCCKrate) psample_pkt_rssi->mimo_singal_strength[0 ] = psample_pkt_rssi->pwdball;
@@ -1684,7 +1684,7 @@ void rtw_store_phy_info(struct adapter *padapter, union recv_frame *prframe)struct rx_raw_rssi *psample_pkt_rssi = &padapter->recvpriv.raw_rssi_info; psample_pkt_rssi->data_rate = pattrib->data_rate; - isCCKrate = (pattrib->data_rate <=DESC_RATE11M ) ? true : false; + isCCKrate = pattrib->data_rate <=DESC_RATE11M ; psample_pkt_rssi->pwdball = pPhyInfo->RxPWDBAll; psample_pkt_rssi->pwr_all = pPhyInfo->RecvSignalPower;
drivers/staging/rtl8723bs/hal/odm_CfoTracking.c +1 -1
@@ -23,7 +23,7 @@ static void odm_SetCrystalCap(void *pDM_VOID, u8 CrystalCap)struct adapter *Adapter = pDM_Odm->Adapter;struct hal_com_data *pHalData =GET_HAL_DATA (Adapter); - bEEPROMCheck = (pHalData->EEPROMVersion >=0x01 ) ? true : false; + bEEPROMCheck = pHalData->EEPROMVersion >=0x01 ;if (pCfoTrack->CrystalCap == CrystalCap)return ;
drivers/staging/rtl8723bs/hal/odm_HWConfig.c +1 -1
@@ -106,7 +106,7 @@ static void odm_RxPhyStatus92CSeries_Parsing(u8 LNA_idx, VGA_idx;PPHY_STATUS_RPT_8192CD_T pPhyStaRpt = (PPHY_STATUS_RPT_8192CD_T )pPhyStatus; - isCCKrate = (pPktinfo->DataRate <=DESC_RATE11M ) ? true : false; + isCCKrate = pPktinfo->DataRate <=DESC_RATE11M ; pPhyInfo->RxMIMOSignalQuality[ODM_RF_PATH_A ] =-1 ; pPhyInfo->RxMIMOSignalQuality[ODM_RF_PATH_B ] =-1 ;
drivers/staging/rtl8723bs/hal/sdio_halinit.c +2 -2
@@ -1019,8 +1019,8 @@ static u32 rtl8723bs_hal_init(struct adapter *padapter)rtw_btcoex_IQKNotify (padapter, true); - restore_iqk_rst = (pwrpriv->bips_processing == true) ? true : false; - b2Ant = pHalData->EEPROMBluetoothAntNum == Ant_x2 ? true : false; + restore_iqk_rst = pwrpriv->bips_processing == true; + b2Ant = pHalData->EEPROMBluetoothAntNum == Ant_x2;PHY_IQCalibrate_8723B (padapter, false, restore_iqk_rst, b2Ant, pHalData->ant_path); pHalData->odmpriv.RFCalibrateInfo.bIQKInitialized = true;
Signature · 1 line
2.7.4
Quoted 35 lines · Aastha Gupta
Remove unnecessary ternary operators in assignments statments.
This patch is with the help of following Coccinelle script:
@@
expression a, b, c;
binary operator op = {==, !=, <=, >=, <, >, &&, ||}; @@c =
- (a op b) ? true : false
+ a op bSigned-off-by Aastha Gupta <[email protected]>---
Changes in v2:
- removed error in Coccinelle script
- corrected checkpatch.pl warnings for the patchdrivers/staging/rtl8723bs/core/rtw_ioctl_set.c | 2 +- drivers/staging/rtl8723bs/core/rtw_pwrctrl.c | 5 +++-- drivers/staging/rtl8723bs/core/rtw_sta_mgt.c | 2 +- drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 2 +- drivers/staging/rtl8723bs/hal/hal_btcoex.c | 4 ++-- drivers/staging/rtl8723bs/hal/hal_com.c | 6 +++--- drivers/staging/rtl8723bs/hal/odm_CfoTracking.c | 2 +- drivers/staging/rtl8723bs/hal/odm_HWConfig.c | 2 +- drivers/staging/rtl8723bs/hal/sdio_halinit.c | 4 ++-- 9 files changed, 15 insertions(+), 14 deletions(-)drivers/staging/rtl8723bs/core/rtw_ioctl_set.c +0
-0
drivers/staging/rtl8723bs/core/rtw_ioctl_set.c u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep) · line 600
Quoted 5 lines
drivers/staging/rtl8723bs/core/rtw_ioctl_set.c +1
-1@@ -597,7 +597,7 @@ u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep)u8 ret = _SUCCESS; bdefaultkey = (wep->KeyIndex &0x40000000 ) >0 ? false : true;/* for ??? */ - btransmitkey = (wep->KeyIndex &0x80000000 ) >0 ? true : false;/* for ??? */ + btransmitkey = (wep->KeyIndex &0x80000000 ) >0 ;/* for ??? */
As the comments suggest, it seems that these two operations are just dead code. The values of these variables are not used subsequently. Maybe they could just be dropped.
An alternative would be to make these variables booleans, in which case their definitions could be !(wep->KeyIndex & 0x40000000) and wep->KeyIndex & 0x80000000, respectively, but since the values are not used there doesn't seem to be much point.
Quoted 31 lines
drivers/staging/rtl8723bs/core/rtw_ioctl_set.c +0
-0keyid = wep->KeyIndex &0x3fffffff ;if (keyid >=4 ) {drivers/staging/rtl8723bs/core/rtw_pwrctrl.c +3
-2@@ -1154,7 +1154,7 @@ void rtw_init_pwrctrl_priv(struct adapter *padapter) pwrctrlpriv->LpsIdleCount =0 ; pwrctrlpriv->power_mgnt = padapter->registrypriv.power_mgnt;/* PS_MODE_MIN; */ - pwrctrlpriv->bLeisurePs = (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt)?true:false; + pwrctrlpriv->bLeisurePs = pwrctrlpriv->power_mgnt !=PS_MODE_ACTIVE ; pwrctrlpriv->bFwCurrentInPSMode = false;@@ -1325,7 +1325,8 @@ int rtw_pm_set_lps(struct adapter *padapter, u8 mode) pwrctrlpriv->LpsIdleCount =2 ; pwrctrlpriv->power_mgnt = mode; - pwrctrlpriv->bLeisurePs = (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt)?true:false; + pwrctrlpriv->bLeisurePs = + pwrctrlpriv->power_mgnt !=PS_MODE_ACTIVE ; } }else ret = -EINVAL ;drivers/staging/rtl8723bs/core/rtw_sta_mgt.c +0
-0
drivers/staging/rtl8723bs/core/rtw_sta_mgt.c u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr) · line 633
Quoted 1 line
drivers/staging/rtl8723bs/core/rtw_sta_mgt.c +0
-0@@ -633,7 +633,7 @@ u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr) res = (match == true) ? false:true;
This is just res = !match
drivers/staging/rtl8723bs/core/rtw_sta_mgt.c u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr) · line 636
Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_sta_mgt.c +1
-1else if (pacl_list->mode ==2 )/* deny unless in accept list */ - res = (match == true) ? true:false; + res = match == true;
This is just res = match. Match is only every true or false. It would be better to make its type bool rather than u8.
drivers/staging/rtl8723bs/core/rtw_wlan_util.c void process_addba_req(struct adapter *padapter, u8 *paddba_req, u8 *addr) · line 1949
Quoted 13 lines
drivers/staging/rtl8723bs/core/rtw_sta_mgt.c +0
-0else res = true;drivers/staging/rtl8723bs/core/rtw_wlan_util.c +1
-1@@ -1946,7 +1946,7 @@ void process_addba_req(struct adapter *padapter, u8 *paddba_req, u8 *addr) preorder_ctrl->indicate_seq =0xffff ;#endif - preorder_ctrl->enable = (pmlmeinfo->bAcceptAddbaReq == true) ? true : false; + preorder_ctrl->enable = pmlmeinfo->bAcceptAddbaReq == true;
The bAcceptAddbaReq field has type bool, so there is no need for the == true either. Drifting a bit further afield, bAcceptAddbaReq uses camel case and encodes the type in the variable name (the initial b), neither of which is wanted for the Linux kernel. Actually as structure with the same name has been fixed in a related driver, and the same fix could be done here.
Quoted 17 lines
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +0
-0} }drivers/staging/rtl8723bs/hal/hal_btcoex.c +1
-1@@ -463,7 +463,7 @@ static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)break ;case BTC_GET_BL_WIFI_UNDER_5G : - *pu8 = (pHalData->CurrentBandType ==1 ) ? true : false; + *pu8 = pHalData->CurrentBandType ==1 ;break ;case BTC_GET_BL_WIFI_AP_MODE_ENABLE :
drivers/staging/rtl8723bs/hal/hal_btcoex.c u8 hal_btcoex_Initialize(struct adapter *padapter) · line 1422
Quoted 7 lines
drivers/staging/rtl8723bs/hal/hal_btcoex.c +1
-1@@ -1417,7 +1417,7 @@ u8 hal_btcoex_Initialize(struct adapter *padapter)memset (&GLBtCoexist,0 ,sizeof (GLBtCoexist)); ret1 =EXhalbtcoutsrc_InitlizeVariables ((void *)padapter); - ret2 = (ret1 == true) ? true : false; + ret2 = ret1 == true;return ret2;
The above appears to be the same as
return EXhalbtcoutsrc_InitlizeVariables((void *)padapter);
with all of the subsequent lines deleted. Indeed EXhalbtcoutsrc_InitlizeVariables also only returns true.
[...] (a bunch of cases that look ok)
drivers/staging/rtl8723bs/hal/sdio_halinit.c static u32 rtl8723bs_hal_init(struct adapter *padapter) · line 1023
Quoted 12 lines
drivers/staging/rtl8723bs/hal/sdio_halinit.c +2
-2@@ -1019,8 +1019,8 @@ static u32 rtl8723bs_hal_init(struct adapter *padapter)rtw_btcoex_IQKNotify (padapter, true); - restore_iqk_rst = (pwrpriv->bips_processing == true) ? true : false; - b2Ant = pHalData->EEPROMBluetoothAntNum == Ant_x2 ? true : false; + restore_iqk_rst = pwrpriv->bips_processing == true; + b2Ant = pHalData->EEPROMBluetoothAntNum == Ant_x2;
Check whether the == true is really necessary, ie whether the bips_processing has boolean type or is only assigned to true or false values.
julia
Quoted 13 lines
drivers/staging/rtl8723bs/hal/sdio_halinit.c +0
-1PHY_IQCalibrate_8723B (padapter, false, restore_iqk_rst, b2Ant, pHalData->ant_path); pHalData->odmpriv.RFCalibrateInfo.bIQKInitialized = true; --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1507402322-28082-1-git-send-email-aastha.gupta4104%40gmail.com.
For more options, visit https://groups.google.com/d/optout.