Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: rtl8723bs: use ARRAY_SIZE

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 <jeremy.lefaure@lse.epita.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jérémy Lefaure and committed by
Greg Kroah-Hartman
60db8d10 2595587d

+68 -48
+3 -2
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
··· 17 17 #include <drv_types.h> 18 18 #include <rtw_debug.h> 19 19 #include <rtw_wifi_regd.h> 20 + #include <linux/kernel.h> 20 21 21 22 22 23 static struct mlme_handler mlme_sta_tbl[] = { ··· 560 559 561 560 index = GetFrameSubType(pframe) >> 4; 562 561 563 - if (index >= (sizeof(mlme_sta_tbl) / sizeof(struct mlme_handler))) { 562 + if (index >= ARRAY_SIZE(mlme_sta_tbl)) { 564 563 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("Currently we do not support reserved sub-fr-type =%d\n", index)); 565 564 return; 566 565 } ··· 2225 2224 2226 2225 category = frame_body[0]; 2227 2226 2228 - for (i = 0; i < sizeof(OnAction_tbl)/sizeof(struct action_handler); i++) { 2227 + for (i = 0; i < ARRAY_SIZE(OnAction_tbl); i++) { 2229 2228 ptable = &OnAction_tbl[i]; 2230 2229 2231 2230 if (category == ptable->num)
+3 -4
drivers/staging/rtl8723bs/core/rtw_rf.c
··· 15 15 #define _RTW_RF_C_ 16 16 17 17 #include <drv_types.h> 18 + #include <linux/kernel.h> 18 19 19 20 20 21 struct ch_freq { ··· 45 44 {216, 5080},/* Japan, means J16 */ 46 45 }; 47 46 48 - static int ch_freq_map_num = (sizeof(ch_freq_map) / sizeof(struct ch_freq)); 49 - 50 47 u32 rtw_ch2freq(u32 channel) 51 48 { 52 49 u8 i; 53 50 u32 freq = 0; 54 51 55 - for (i = 0; i < ch_freq_map_num; i++) { 52 + for (i = 0; i < ARRAY_SIZE(ch_freq_map); i++) { 56 53 if (channel == ch_freq_map[i].channel) { 57 54 freq = ch_freq_map[i].frequency; 58 55 break; 59 56 } 60 57 } 61 - if (i == ch_freq_map_num) 58 + if (i == ARRAY_SIZE(ch_freq_map)) 62 59 freq = 2412; 63 60 64 61 return freq;
+4 -5
drivers/staging/rtl8723bs/hal/HalHWImg8723B_BB.c
··· 13 13 * 14 14 ******************************************************************************/ 15 15 16 - 16 + #include <linux/kernel.h> 17 17 #include "odm_precomp.h" 18 18 19 19 static bool CheckPositive( ··· 268 268 void ODM_ReadAndConfig_MP_8723B_AGC_TAB(PDM_ODM_T pDM_Odm) 269 269 { 270 270 u32 i = 0; 271 - u32 ArrayLen = sizeof(Array_MP_8723B_AGC_TAB)/sizeof(u32); 271 + u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_AGC_TAB); 272 272 u32 *Array = Array_MP_8723B_AGC_TAB; 273 273 274 274 ODM_RT_TRACE( ··· 537 537 void ODM_ReadAndConfig_MP_8723B_PHY_REG(PDM_ODM_T pDM_Odm) 538 538 { 539 539 u32 i = 0; 540 - u32 ArrayLen = sizeof(Array_MP_8723B_PHY_REG)/sizeof(u32); 540 + u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_PHY_REG); 541 541 u32 *Array = Array_MP_8723B_PHY_REG; 542 542 543 543 ODM_RT_TRACE( ··· 617 617 void ODM_ReadAndConfig_MP_8723B_PHY_REG_PG(PDM_ODM_T pDM_Odm) 618 618 { 619 619 u32 i = 0; 620 - u32 ArrayLen = sizeof(Array_MP_8723B_PHY_REG_PG)/sizeof(u32); 621 620 u32 *Array = Array_MP_8723B_PHY_REG_PG; 622 621 623 622 ODM_RT_TRACE( ··· 629 630 pDM_Odm->PhyRegPgVersion = 1; 630 631 pDM_Odm->PhyRegPgValueType = PHY_REG_PG_EXACT_VALUE; 631 632 632 - for (i = 0; i < ArrayLen; i += 6) { 633 + for (i = 0; i < ARRAY_SIZE(Array_MP_8723B_PHY_REG_PG); i += 6) { 633 634 u32 v1 = Array[i]; 634 635 u32 v2 = Array[i+1]; 635 636 u32 v3 = Array[i+2];
+2 -2
drivers/staging/rtl8723bs/hal/HalHWImg8723B_MAC.c
··· 13 13 * 14 14 ******************************************************************************/ 15 15 16 - 16 + #include <linux/kernel.h> 17 17 #include "odm_precomp.h" 18 18 19 19 static bool CheckPositive( ··· 239 239 void ODM_ReadAndConfig_MP_8723B_MAC_REG(PDM_ODM_T pDM_Odm) 240 240 { 241 241 u32 i = 0; 242 - u32 ArrayLen = sizeof(Array_MP_8723B_MAC_REG)/sizeof(u32); 242 + u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_MAC_REG); 243 243 u32 *Array = Array_MP_8723B_MAC_REG; 244 244 245 245 ODM_RT_TRACE(
+3 -4
drivers/staging/rtl8723bs/hal/HalHWImg8723B_RF.c
··· 13 13 * 14 14 ******************************************************************************/ 15 15 16 - 16 + #include <linux/kernel.h> 17 17 #include "odm_precomp.h" 18 18 19 19 static bool CheckPositive( ··· 270 270 void ODM_ReadAndConfig_MP_8723B_RadioA(PDM_ODM_T pDM_Odm) 271 271 { 272 272 u32 i = 0; 273 - u32 ArrayLen = sizeof(Array_MP_8723B_RadioA)/sizeof(u32); 273 + u32 ArrayLen = ARRAY_SIZE(Array_MP_8723B_RadioA); 274 274 u32 *Array = Array_MP_8723B_RadioA; 275 275 276 276 ODM_RT_TRACE( ··· 766 766 void ODM_ReadAndConfig_MP_8723B_TXPWR_LMT(PDM_ODM_T pDM_Odm) 767 767 { 768 768 u32 i = 0; 769 - u32 ArrayLen = sizeof(Array_MP_8723B_TXPWR_LMT)/sizeof(u8 *); 770 769 u8 **Array = Array_MP_8723B_TXPWR_LMT; 771 770 772 771 ODM_RT_TRACE( ··· 775 776 ("===> ODM_ReadAndConfig_MP_8723B_TXPWR_LMT\n") 776 777 ); 777 778 778 - for (i = 0; i < ArrayLen; i += 7) { 779 + for (i = 0; i < ARRAY_SIZE(Array_MP_8723B_TXPWR_LMT); i += 7) { 779 780 u8 *regulation = Array[i]; 780 781 u8 *band = Array[i+1]; 781 782 u8 *bandwidth = Array[i+2];
+2 -2
drivers/staging/rtl8723bs/hal/hal_com.c
··· 14 14 ******************************************************************************/ 15 15 #define _HAL_COM_C_ 16 16 17 + #include <linux/kernel.h> 17 18 #include <drv_types.h> 18 19 #include <rtw_debug.h> 19 20 #include "hal_com_h2c.h" ··· 1717 1716 { 1718 1717 u8 value = padapter->eeprompriv.EEPROMRFGainOffset; 1719 1718 u32 res, i = 0; 1720 - u32 ArrayLen = sizeof(Array_kfreemap)/sizeof(u32); 1721 1719 u32 *Array = Array_kfreemap; 1722 1720 u32 v1 = 0, v2 = 0, target = 0; 1723 1721 /* DBG_871X("+%s value: 0x%02x+\n", __func__, value); */ ··· 1729 1729 res &= 0xfff87fff; 1730 1730 DBG_871X("Offset RF Gain. before reg 0x7f = 0x%08x\n", res); 1731 1731 /* res &= 0xfff87fff; */ 1732 - for (i = 0; i < ArrayLen; i += 2) { 1732 + for (i = 0; i < ARRAY_SIZE(Array_kfreemap); i += 2) { 1733 1733 v1 = Array[i]; 1734 1734 v2 = Array[i+1]; 1735 1735 if (v1 == padapter->eeprompriv.EEPROMRFGainVal) {
+45 -24
drivers/staging/rtl8723bs/hal/hal_com_phycfg.c
··· 17 17 #include <drv_types.h> 18 18 #include <rtw_debug.h> 19 19 #include <hal_data.h> 20 + #include <linux/kernel.h> 20 21 21 22 u8 PHY_GetTxPowerByRateBase(struct adapter *Adapter, u8 Band, u8 RfPath, 22 23 u8 TxNum, enum RATE_SECTION RateSection) ··· 861 860 for (txNum = RF_1TX; txNum < RF_MAX_TX_NUM; ++txNum) { 862 861 /* CCK */ 863 862 base = PHY_GetTxPowerByRate(padapter, band, path, txNum, MGN_11M); 864 - for (i = 0; i < sizeof(cckRates); ++i) { 863 + for (i = 0; i < ARRAY_SIZE(cckRates); ++i) { 865 864 value = PHY_GetTxPowerByRate(padapter, band, path, txNum, cckRates[i]); 866 865 PHY_SetTxPowerByRate(padapter, band, path, txNum, cckRates[i], value - base); 867 866 } ··· 940 939 if (RateSection == CCK) { 941 940 u8 cckRates[] = {MGN_1M, MGN_2M, MGN_5_5M, MGN_11M}; 942 941 if (pHalData->CurrentBandType == BAND_ON_2_4G) 943 - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, 944 - cckRates, sizeof(cckRates)/sizeof(u8)); 942 + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, 943 + pHalData->CurrentChannelBW, 944 + Channel, cckRates, 945 + ARRAY_SIZE(cckRates)); 945 946 946 947 } else if (RateSection == OFDM) { 947 948 u8 ofdmRates[] = {MGN_6M, MGN_9M, MGN_12M, MGN_18M, MGN_24M, MGN_36M, MGN_48M, MGN_54M}; 948 - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, 949 - ofdmRates, sizeof(ofdmRates)/sizeof(u8)); 949 + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, 950 + pHalData->CurrentChannelBW, 951 + Channel, ofdmRates, 952 + ARRAY_SIZE(ofdmRates)); 950 953 951 954 } else if (RateSection == HT_MCS0_MCS7) { 952 955 u8 htRates1T[] = {MGN_MCS0, MGN_MCS1, MGN_MCS2, MGN_MCS3, MGN_MCS4, MGN_MCS5, MGN_MCS6, MGN_MCS7}; 953 - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, 954 - htRates1T, sizeof(htRates1T)/sizeof(u8)); 956 + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, 957 + pHalData->CurrentChannelBW, 958 + Channel, htRates1T, 959 + ARRAY_SIZE(htRates1T)); 955 960 956 961 } else if (RateSection == HT_MCS8_MCS15) { 957 962 u8 htRates2T[] = {MGN_MCS8, MGN_MCS9, MGN_MCS10, MGN_MCS11, MGN_MCS12, MGN_MCS13, MGN_MCS14, MGN_MCS15}; 958 - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, 959 - htRates2T, sizeof(htRates2T)/sizeof(u8)); 963 + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, 964 + pHalData->CurrentChannelBW, 965 + Channel, htRates2T, 966 + ARRAY_SIZE(htRates2T)); 960 967 961 968 } else if (RateSection == HT_MCS16_MCS23) { 962 969 u8 htRates3T[] = {MGN_MCS16, MGN_MCS17, MGN_MCS18, MGN_MCS19, MGN_MCS20, MGN_MCS21, MGN_MCS22, MGN_MCS23}; 963 - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, 964 - htRates3T, sizeof(htRates3T)/sizeof(u8)); 970 + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, 971 + pHalData->CurrentChannelBW, 972 + Channel, htRates3T, 973 + ARRAY_SIZE(htRates3T)); 965 974 966 975 } else if (RateSection == HT_MCS24_MCS31) { 967 976 u8 htRates4T[] = {MGN_MCS24, MGN_MCS25, MGN_MCS26, MGN_MCS27, MGN_MCS28, MGN_MCS29, MGN_MCS30, MGN_MCS31}; 968 - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, 969 - htRates4T, sizeof(htRates4T)/sizeof(u8)); 977 + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, 978 + pHalData->CurrentChannelBW, 979 + Channel, htRates4T, 980 + ARRAY_SIZE(htRates4T)); 970 981 971 982 } else if (RateSection == VHT_1SSMCS0_1SSMCS9) { 972 983 u8 vhtRates1T[] = {MGN_VHT1SS_MCS0, MGN_VHT1SS_MCS1, MGN_VHT1SS_MCS2, MGN_VHT1SS_MCS3, MGN_VHT1SS_MCS4, 973 984 MGN_VHT1SS_MCS5, MGN_VHT1SS_MCS6, MGN_VHT1SS_MCS7, MGN_VHT1SS_MCS8, MGN_VHT1SS_MCS9}; 974 - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, 975 - vhtRates1T, sizeof(vhtRates1T)/sizeof(u8)); 985 + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, 986 + pHalData->CurrentChannelBW, 987 + Channel, vhtRates1T, 988 + ARRAY_SIZE(vhtRates1T)); 976 989 977 990 } else if (RateSection == VHT_2SSMCS0_2SSMCS9) { 978 991 u8 vhtRates2T[] = {MGN_VHT2SS_MCS0, MGN_VHT2SS_MCS1, MGN_VHT2SS_MCS2, MGN_VHT2SS_MCS3, MGN_VHT2SS_MCS4, 979 992 MGN_VHT2SS_MCS5, MGN_VHT2SS_MCS6, MGN_VHT2SS_MCS7, MGN_VHT2SS_MCS8, MGN_VHT2SS_MCS9}; 980 993 981 - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, 982 - vhtRates2T, sizeof(vhtRates2T)/sizeof(u8)); 994 + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, 995 + pHalData->CurrentChannelBW, 996 + Channel, vhtRates2T, 997 + ARRAY_SIZE(vhtRates2T)); 983 998 } else if (RateSection == VHT_3SSMCS0_3SSMCS9) { 984 999 u8 vhtRates3T[] = {MGN_VHT3SS_MCS0, MGN_VHT3SS_MCS1, MGN_VHT3SS_MCS2, MGN_VHT3SS_MCS3, MGN_VHT3SS_MCS4, 985 1000 MGN_VHT3SS_MCS5, MGN_VHT3SS_MCS6, MGN_VHT3SS_MCS7, MGN_VHT3SS_MCS8, MGN_VHT3SS_MCS9}; 986 1001 987 - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, 988 - vhtRates3T, sizeof(vhtRates3T)/sizeof(u8)); 1002 + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, 1003 + pHalData->CurrentChannelBW, 1004 + Channel, vhtRates3T, 1005 + ARRAY_SIZE(vhtRates3T)); 989 1006 } else if (RateSection == VHT_4SSMCS0_4SSMCS9) { 990 1007 u8 vhtRates4T[] = {MGN_VHT4SS_MCS0, MGN_VHT4SS_MCS1, MGN_VHT4SS_MCS2, MGN_VHT4SS_MCS3, MGN_VHT4SS_MCS4, 991 1008 MGN_VHT4SS_MCS5, MGN_VHT4SS_MCS6, MGN_VHT4SS_MCS7, MGN_VHT4SS_MCS8, MGN_VHT4SS_MCS9}; 992 1009 993 - PHY_SetTxPowerIndexByRateArray(padapter, RFPath, pHalData->CurrentChannelBW, Channel, 994 - vhtRates4T, sizeof(vhtRates4T)/sizeof(u8)); 1010 + PHY_SetTxPowerIndexByRateArray(padapter, RFPath, 1011 + pHalData->CurrentChannelBW, 1012 + Channel, vhtRates4T, 1013 + ARRAY_SIZE(vhtRates4T)); 995 1014 } else 996 1015 DBG_871X("Invalid RateSection %d in %s", RateSection, __func__); 997 1016 } ··· 1033 1012 } else { 1034 1013 bIn24G = false; 1035 1014 1036 - for (i = 0; i < sizeof(channel5G)/sizeof(u8); ++i) { 1015 + for (i = 0; i < ARRAY_SIZE(channel5G); ++i) { 1037 1016 if (channel5G[i] == Channel) { 1038 1017 *ChannelIdx = i; 1039 1018 return bIn24G; ··· 1170 1149 } else if (BandWidth == CHANNEL_WIDTH_80) { /* BW80-1S, BW80-2S */ 1171 1150 /* <20121220, Kordan> Get the index of array "Index5G_BW80_Base". */ 1172 1151 u8 channel5G_80M[CHANNEL_MAX_NUMBER_5G_80M] = {42, 58, 106, 122, 138, 155, 171}; 1173 - for (i = 0; i < sizeof(channel5G_80M)/sizeof(u8); ++i) 1152 + for (i = 0; i < ARRAY_SIZE(channel5G_80M); ++i) 1174 1153 if (channel5G_80M[i] == Channel) 1175 1154 chnlIdx = i; 1176 1155 ··· 1609 1588 if (Band == BAND_ON_2_4G) 1610 1589 channelIndex = Channel - 1; 1611 1590 else if (Band == BAND_ON_5G) { 1612 - for (i = 0; i < sizeof(channel5G)/sizeof(u8); ++i) { 1591 + for (i = 0; i < ARRAY_SIZE(channel5G); ++i) { 1613 1592 if (channel5G[i] == Channel) 1614 1593 channelIndex = i; 1615 1594 }
+6 -5
drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
··· 18 18 #include <rtw_debug.h> 19 19 #include <rtw_mp.h> 20 20 #include <linux/jiffies.h> 21 + #include <linux/kernel.h> 21 22 22 23 #define RTL_IOCTL_WPA_SUPPLICANT (SIOCIWFIRSTPRIV+30) 23 24 ··· 5018 5017 5019 5018 struct iw_handler_def rtw_handlers_def = { 5020 5019 .standard = rtw_handlers, 5021 - .num_standard = sizeof(rtw_handlers) / sizeof(iw_handler), 5020 + .num_standard = ARRAY_SIZE(rtw_handlers), 5022 5021 #if defined(CONFIG_WEXT_PRIV) 5023 5022 .private = rtw_private_handler, 5024 5023 .private_args = (struct iw_priv_args *)rtw_private_args, 5025 - .num_private = sizeof(rtw_private_handler) / sizeof(iw_handler), 5026 - .num_private_args = sizeof(rtw_private_args) / sizeof(struct iw_priv_args), 5024 + .num_private = ARRAY_SIZE(rtw_private_handler), 5025 + .num_private_args = ARRAY_SIZE(rtw_private_args), 5027 5026 #endif 5028 5027 .get_wireless_stats = rtw_get_wireless_stats, 5029 5028 }; ··· 5110 5109 5111 5110 priv = rtw_private_handler; 5112 5111 priv_args = rtw_private_args; 5113 - num_priv = sizeof(rtw_private_handler) / sizeof(iw_handler); 5114 - num_priv_args = sizeof(rtw_private_args) / sizeof(struct iw_priv_args); 5112 + num_priv = ARRAY_SIZE(rtw_private_handler); 5113 + num_priv_args = ARRAY_SIZE(rtw_private_args); 5115 5114 5116 5115 if (num_priv_args == 0) { 5117 5116 err = -EOPNOTSUPP;