From 60db8d10ee3339840d88e57605276bb568af6031 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9my=20Lefaure?= Date: Sun, 1 Oct 2017 15:30:55 -0400 Subject: [PATCH] staging: rtl8723bs: use ARRAY_SIZE MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Using the ARRAY_SIZE macro improves the readability of the code. Also, it is not always useful to use a variable to store this constant calculated at compile time. Found with Coccinelle with the following semantic patch: @r depends on (org || report)@ type T; T[] E; position p; @@ ( (sizeof(E)@p /sizeof(*E)) | (sizeof(E)@p /sizeof(E[...])) | (sizeof(E)@p /sizeof(T)) ) Signed-off-by: Jérémy Lefaure Signed-off-by: Greg Kroah-Hartman --- drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 5 +- drivers/staging/rtl8723bs/core/rtw_rf.c | 7 +- .../staging/rtl8723bs/hal/HalHWImg8723B_BB.c | 9 ++- .../staging/rtl8723bs/hal/HalHWImg8723B_MAC.c | 4 +- .../staging/rtl8723bs/hal/HalHWImg8723B_RF.c | 7 +- drivers/staging/rtl8723bs/hal/hal_com.c | 4 +- .../staging/rtl8723bs/hal/hal_com_phycfg.c | 69 ++++++++++++------- .../staging/rtl8723bs/os_dep/ioctl_linux.c | 11 +-- 8 files changed, 68 insertions(+), 48 deletions(-) diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c index 9f0921b2779a..355ce9b19d1c 100644 --- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c @@ -17,6 +17,7 @@ #include #include #include +#include static struct mlme_handler mlme_sta_tbl[] = { @@ -559,7 +560,7 @@ void mgt_dispatcher(struct adapter *padapter, union recv_frame *precv_frame) index = GetFrameSubType(pframe) >> 4; - if (index >= (sizeof(mlme_sta_tbl) / sizeof(struct mlme_handler))) { + if (index >= ARRAY_SIZE(mlme_sta_tbl)) { RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("Currently we do not support reserved sub-fr-type =%d\n", index)); return; } @@ -2224,7 +2225,7 @@ unsigned int OnAction(struct adapter *padapter, union recv_frame *precv_frame) category = frame_body[0]; - for (i = 0; i < sizeof(OnAction_tbl)/sizeof(struct action_handler); i++) { + for (i = 0; i < ARRAY_SIZE(OnAction_tbl); i++) { ptable = &OnAction_tbl[i]; if (category == ptable->num) diff --git a/drivers/staging/rtl8723bs/core/rtw_rf.c b/drivers/staging/rtl8723bs/core/rtw_rf.c index b87ea4e388c0..07f5577cc073 100644 --- a/drivers/staging/rtl8723bs/core/rtw_rf.c +++ b/drivers/staging/rtl8723bs/core/rtw_rf.c @@ -15,6 +15,7 @@ #define _RTW_RF_C_ #include +#include struct ch_freq { @@ -44,20 +45,18 @@ static struct ch_freq ch_freq_map[] = { {216, 5080},/* Japan, means J16 */ }; -static int ch_freq_map_num = (sizeof(ch_freq_map) / sizeof(struct ch_freq)); - u32 rtw_ch2freq(u32 channel) { u8 i; u32 freq = 0; - for (i = 0; i < ch_freq_map_num; i++) { + for (i = 0; i < ARRAY_SIZE(ch_freq_map); i++) { if (channel == ch_freq_map[i].channel) { freq = ch_freq_map[i].frequency; break; } } - if (i == ch_freq_map_num) + if (i == ARRAY_SIZE(ch_freq_map)) freq = 2412; return freq; diff --git a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c index 51d4219177d3..951585467ab1 100644 --- a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c +++ b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c @@ -13,7 +13,7 @@ * ******************************************************************************/ - +#include #include "odm_precomp.h" static bool CheckPositive( @@ -268,7 +268,7 @@ static u32 Array_MP_8723B_AGC_TAB[] = { void ODM_ReadAndConfig_MP_8723B_AGC_TAB(PDM_ODM_T pDM_Odm) { u32 i = 0; - u32 ArrayLen = sizeof(Array_MP_8723B_AGC_TAB)/sizeof(u32); + u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_AGC_TAB); u32 *Array = Array_MP_8723B_AGC_TAB; ODM_RT_TRACE( @@ -537,7 +537,7 @@ static u32 Array_MP_8723B_PHY_REG[] = { void ODM_ReadAndConfig_MP_8723B_PHY_REG(PDM_ODM_T pDM_Odm) { u32 i = 0; - u32 ArrayLen = sizeof(Array_MP_8723B_PHY_REG)/sizeof(u32); + u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_PHY_REG); u32 *Array = Array_MP_8723B_PHY_REG; ODM_RT_TRACE( @@ -617,7 +617,6 @@ static u32 Array_MP_8723B_PHY_REG_PG[] = { void ODM_ReadAndConfig_MP_8723B_PHY_REG_PG(PDM_ODM_T pDM_Odm) { u32 i = 0; - u32 ArrayLen = sizeof(Array_MP_8723B_PHY_REG_PG)/sizeof(u32); u32 *Array = Array_MP_8723B_PHY_REG_PG; ODM_RT_TRACE( @@ -630,7 +629,7 @@ void ODM_ReadAndConfig_MP_8723B_PHY_REG_PG(PDM_ODM_T pDM_Odm) pDM_Odm->PhyRegPgVersion = 1; pDM_Odm->PhyRegPgValueType = PHY_REG_PG_EXACT_VALUE; - for (i = 0; i < ArrayLen; i += 6) { + for (i = 0; i < ARRAY_SIZE(Array_MP_8723B_PHY_REG_PG); i += 6) { u32 v1 = Array[i]; u32 v2 = Array[i+1]; u32 v3 = Array[i+2]; diff --git a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.c b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.c index b868e26f20ac..7f8afa1be1ca 100644 --- a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.c +++ b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.c @@ -13,7 +13,7 @@ * ******************************************************************************/ - +#include #include "odm_precomp.h" static bool CheckPositive( @@ -239,7 +239,7 @@ static u32 Array_MP_8723B_MAC_REG[] = { void ODM_ReadAndConfig_MP_8723B_MAC_REG(PDM_ODM_T pDM_Odm) { u32 i = 0; - u32 ArrayLen = sizeof(Array_MP_8723B_MAC_REG)/sizeof(u32); + u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_MAC_REG); u32 *Array = Array_MP_8723B_MAC_REG; ODM_RT_TRACE( diff --git a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.c b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.c index 84a0be7ba697..fadfcbd91858 100644 --- a/drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.c +++ b/drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.c @@ -13,7 +13,7 @@ * ******************************************************************************/ - +#include #include "odm_precomp.h" static bool CheckPositive( @@ -270,7 +270,7 @@ static u32 Array_MP_8723B_RadioA[] = { void ODM_ReadAndConfig_MP_8723B_RadioA(PDM_ODM_T pDM_Odm) { u32 i = 0; - u32 ArrayLen = sizeof(Array_MP_8723B_RadioA)/sizeof(u32); + u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_RadioA); u32 *Array = Array_MP_8723B_RadioA; ODM_RT_TRACE( @@ -766,7 +766,6 @@ static u8 *Array_MP_8723B_TXPWR_LMT[] = { void ODM_ReadAndConfig_MP_8723B_TXPWR_LMT(PDM_ODM_T pDM_Odm) { u32 i = 0; - u32 ArrayLen = sizeof(Array_MP_8723B_TXPWR_LMT)/sizeof(u8 *); u8 **Array = Array_MP_8723B_TXPWR_LMT; ODM_RT_TRACE( @@ -776,7 +775,7 @@ void ODM_ReadAndConfig_MP_8723B_TXPWR_LMT(PDM_ODM_T pDM_Odm) ("===> ODM_ReadAndConfig_MP_8723B_TXPWR_LMT\n") ); - for (i = 0; i < ArrayLen; i += 7) { + for (i = 0; i < ARRAY_SIZE(Array_MP_8723B_TXPWR_LMT); i += 7) { u8 *regulation = Array[i]; u8 *band = Array[i+1]; u8 *bandwidth = Array[i+2]; diff --git a/drivers/staging/rtl8723bs/hal/hal_com.c b/drivers/staging/rtl8723bs/hal/hal_com.c index 3e63b6d9c097..03554a4156d9 100644 --- a/drivers/staging/rtl8723bs/hal/hal_com.c +++ b/drivers/staging/rtl8723bs/hal/hal_com.c @@ -14,6 +14,7 @@ ******************************************************************************/ #define _HAL_COM_C_ +#include #include #include #include "hal_com_h2c.h" @@ -1716,7 +1717,6 @@ void rtw_bb_rf_gain_offset(struct adapter *padapter) { u8 value = padapter->eeprompriv.EEPROMRFGainOffset; u32 res, i = 0; - u32 ArrayLen = sizeof(Array_kfreemap)/sizeof(u32); u32 *Array = Array_kfreemap; u32 v1 = 0, v2 = 0, target = 0; /* DBG_871X("+%s value: 0x%02x+\n", __func__, value); */ @@ -1729,7 +1729,7 @@ void rtw_bb_rf_gain_offset(struct adapter *padapter) res &= 0xfff87fff; DBG_871X("Offset RF Gain. before reg 0x7f = 0x%08x\n", res); /* res &= 0xfff87fff; */ - for (i = 0; i < ArrayLen; i += 2) { + for (i = 0; i < ARRAY_SIZE(Array_kfreemap); i += 2) { v1 = Array[i]; v2 = Array[i+1]; if (v1 == padapter->eeprompriv.EEPROMRFGainVal) { diff --git a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c index 566b6f0997da..e6787c22e00b 100644 --- a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +++ b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c @@ -17,6 +17,7 @@ #include #include #include +#include u8 PHY_GetTxPowerByRateBase(struct adapter *Adapter, u8 Band, u8 RfPath, u8 TxNum, enum RATE_SECTION RateSection) @@ -860,7 +861,7 @@ struct adapter *padapter for (txNum = RF_1TX; txNum < RF_MAX_TX_NUM; ++txNum) { /* CCK */ base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_11M); - for (i = 0; i < sizeof(cckRates); ++i) { + for (i = 0; i < ARRAY_SIZE(cckRates); ++i) { value = PHY_GetTxPowerByRate(padapter, band, path, txNum, cckRates[i]); PHY_SetTxPowerByRate(padapter, band, path, txNum, cckRates[i], value - base); } @@ -939,58 +940,78 @@ void PHY_SetTxPowerIndexByRateSection( if (RateSection == CCK) { u8 cckRates[] = {MGN_1M, MGN_2M, MGN_5_5M, MGN_11M}; if (pHalData->CurrentBandType == BAND_ON_2_4G) - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, - cckRates, sizeof(cckRates)/sizeof(u8)); + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, + pHalData->CurrentChannelBW, + Channel, cckRates, + ARRAY_SIZE(cckRates)); } else if (RateSection == OFDM) { u8 ofdmRates[] = {MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M}; - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, - ofdmRates, sizeof(ofdmRates)/sizeof(u8)); + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, + pHalData->CurrentChannelBW, + Channel, ofdmRates, + ARRAY_SIZE(ofdmRates)); } else if (RateSection == HT_MCS0_MCS7) { u8 htRates1T[] = {MGN_MCS0, MGN_MCS1, MGN_MCS2, MGN_MCS3, MGN_MCS4, MGN_MCS5, MGN_MCS6, MGN_MCS7}; - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, - htRates1T, sizeof(htRates1T)/sizeof(u8)); + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, + pHalData->CurrentChannelBW, + Channel, htRates1T, + ARRAY_SIZE(htRates1T)); } else if (RateSection == HT_MCS8_MCS15) { u8 htRates2T[] = {MGN_MCS8, MGN_MCS9, MGN_MCS10, MGN_MCS11, MGN_MCS12, MGN_MCS13, MGN_MCS14, MGN_MCS15}; - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, - htRates2T, sizeof(htRates2T)/sizeof(u8)); + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, + pHalData->CurrentChannelBW, + Channel, htRates2T, + ARRAY_SIZE(htRates2T)); } else if (RateSection == HT_MCS16_MCS23) { u8 htRates3T[] = {MGN_MCS16, MGN_MCS17, MGN_MCS18, MGN_MCS19, MGN_MCS20, MGN_MCS21, MGN_MCS22, MGN_MCS23}; - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, - htRates3T, sizeof(htRates3T)/sizeof(u8)); + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, + pHalData->CurrentChannelBW, + Channel, htRates3T, + ARRAY_SIZE(htRates3T)); } else if (RateSection == HT_MCS24_MCS31) { u8 htRates4T[] = {MGN_MCS24, MGN_MCS25, MGN_MCS26, MGN_MCS27, MGN_MCS28, MGN_MCS29, MGN_MCS30, MGN_MCS31}; - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, - htRates4T, sizeof(htRates4T)/sizeof(u8)); + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, + pHalData->CurrentChannelBW, + Channel, htRates4T, + ARRAY_SIZE(htRates4T)); } else if (RateSection == VHT_1SSMCS0_1SSMCS9) { u8 vhtRates1T[] = {MGN_VHT1SS_MCS0, MGN_VHT1SS_MCS1, MGN_VHT1SS_MCS2, MGN_VHT1SS_MCS3, MGN_VHT1SS_MCS4, MGN_VHT1SS_MCS5, MGN_VHT1SS_MCS6, MGN_VHT1SS_MCS7, MGN_VHT1SS_MCS8, MGN_VHT1SS_MCS9}; - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, - vhtRates1T, sizeof(vhtRates1T)/sizeof(u8)); + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, + pHalData->CurrentChannelBW, + Channel, vhtRates1T, + ARRAY_SIZE(vhtRates1T)); } else if (RateSection == VHT_2SSMCS0_2SSMCS9) { u8 vhtRates2T[] = {MGN_VHT2SS_MCS0, MGN_VHT2SS_MCS1, MGN_VHT2SS_MCS2, MGN_VHT2SS_MCS3, MGN_VHT2SS_MCS4, MGN_VHT2SS_MCS5, MGN_VHT2SS_MCS6, MGN_VHT2SS_MCS7, MGN_VHT2SS_MCS8, MGN_VHT2SS_MCS9}; - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, - vhtRates2T, sizeof(vhtRates2T)/sizeof(u8)); + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, + pHalData->CurrentChannelBW, + Channel, vhtRates2T, + ARRAY_SIZE(vhtRates2T)); } else if (RateSection == VHT_3SSMCS0_3SSMCS9) { u8 vhtRates3T[] = {MGN_VHT3SS_MCS0, MGN_VHT3SS_MCS1, MGN_VHT3SS_MCS2, MGN_VHT3SS_MCS3, MGN_VHT3SS_MCS4, MGN_VHT3SS_MCS5, MGN_VHT3SS_MCS6, MGN_VHT3SS_MCS7, MGN_VHT3SS_MCS8, MGN_VHT3SS_MCS9}; - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, - vhtRates3T, sizeof(vhtRates3T)/sizeof(u8)); + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, + pHalData->CurrentChannelBW, + Channel, vhtRates3T, + ARRAY_SIZE(vhtRates3T)); } else if (RateSection == VHT_4SSMCS0_4SSMCS9) { u8 vhtRates4T[] = {MGN_VHT4SS_MCS0, MGN_VHT4SS_MCS1, MGN_VHT4SS_MCS2, MGN_VHT4SS_MCS3, MGN_VHT4SS_MCS4, MGN_VHT4SS_MCS5, MGN_VHT4SS_MCS6, MGN_VHT4SS_MCS7, MGN_VHT4SS_MCS8, MGN_VHT4SS_MCS9}; - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, - vhtRates4T, sizeof(vhtRates4T)/sizeof(u8)); + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, + pHalData->CurrentChannelBW, + Channel, vhtRates4T, + ARRAY_SIZE(vhtRates4T)); } else DBG_871X("Invalid RateSection %d in %s", RateSection, __func__); } @@ -1012,7 +1033,7 @@ static bool phy_GetChnlIndex(u8 Channel, u8 *ChannelIdx) } else { bIn24G = false; - for (i = 0; i < sizeof(channel5G)/sizeof(u8); ++i) { + for (i = 0; i < ARRAY_SIZE(channel5G); ++i) { if (channel5G[i] == Channel) { *ChannelIdx = i; return bIn24G; @@ -1149,7 +1170,7 @@ u8 PHY_GetTxPowerIndexBase( } else if (BandWidth == CHANNEL_WIDTH_80) { /* BW80-1S, BW80-2S */ /* <20121220, Kordan> Get the index of array "Index5G_BW80_Base". */ u8 channel5G_80M[CHANNEL_MAX_NUMBER_5G_80M] = {42, 58, 106, 122, 138, 155, 171}; - for (i = 0; i < sizeof(channel5G_80M)/sizeof(u8); ++i) + for (i = 0; i < ARRAY_SIZE(channel5G_80M); ++i) if (channel5G_80M[i] == Channel) chnlIdx = i; @@ -1588,7 +1609,7 @@ static s8 phy_GetChannelIndexOfTxPowerLimit(u8 Band, u8 Channel) if (Band == BAND_ON_2_4G) channelIndex = Channel - 1; else if (Band == BAND_ON_5G) { - for (i = 0; i < sizeof(channel5G)/sizeof(u8); ++i) { + for (i = 0; i < ARRAY_SIZE(channel5G); ++i) { if (channel5G[i] == Channel) channelIndex = i; } diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c index 6a8f805c0b28..3fca0c2d4c8d 100644 --- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c +++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c @@ -18,6 +18,7 @@ #include #include #include +#include #define RTL_IOCTL_WPA_SUPPLICANT (SIOCIWFIRSTPRIV+30) @@ -5017,12 +5018,12 @@ static struct iw_statistics *rtw_get_wireless_stats(struct net_device *dev) struct iw_handler_def rtw_handlers_def = { .standard = rtw_handlers, - .num_standard = sizeof(rtw_handlers) / sizeof(iw_handler), + .num_standard = ARRAY_SIZE(rtw_handlers), #if defined(CONFIG_WEXT_PRIV) .private = rtw_private_handler, .private_args = (struct iw_priv_args *)rtw_private_args, - .num_private = sizeof(rtw_private_handler) / sizeof(iw_handler), - .num_private_args = sizeof(rtw_private_args) / sizeof(struct iw_priv_args), + .num_private = ARRAY_SIZE(rtw_private_handler), + .num_private_args = ARRAY_SIZE(rtw_private_args), #endif .get_wireless_stats = rtw_get_wireless_stats, }; @@ -5109,8 +5110,8 @@ static int rtw_ioctl_wext_private(struct net_device *dev, union iwreq_data *wrq_ priv = rtw_private_handler; priv_args = rtw_private_args; - num_priv = sizeof(rtw_private_handler) / sizeof(iw_handler); - num_priv_args = sizeof(rtw_private_args) / sizeof(struct iw_priv_args); + num_priv = ARRAY_SIZE(rtw_private_handler); + num_priv_args = ARRAY_SIZE(rtw_private_args); if (num_priv_args == 0) { err = -EOPNOTSUPP; -- 2.45.2