diff options
author | Jérémy Lefaure <jeremy.lefaure@lse.epita.fr> | 2017-10-01 15:30:56 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-10-03 18:34:56 +0200 |
commit | 2595587d7e227a9181750110f50e02a2511821dd (patch) | |
tree | de11fa0d4540b41b08e47d4c81beb36a9aa9606f /drivers/staging/rtlwifi | |
parent | 8dabf52ffb6445fa5bcc8b6d2ecb615f60d0dd12 (diff) | |
download | linux-stable-2595587d7e227a9181750110f50e02a2511821dd.tar.gz linux-stable-2595587d7e227a9181750110f50e02a2511821dd.tar.bz2 linux-stable-2595587d7e227a9181750110f50e02a2511821dd.zip |
staging: rtlwifi: use ARRAY_SIZE
Using the ARRAY_SIZE macro improves the readability of the code. Also,
it is useless 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>
Diffstat (limited to 'drivers/staging/rtlwifi')
4 files changed, 13 insertions, 18 deletions
diff --git a/drivers/staging/rtlwifi/phydm/phydm_debug.c b/drivers/staging/rtlwifi/phydm/phydm_debug.c index a5f90afdae9b..d4dd0fd3d1c7 100644 --- a/drivers/staging/rtlwifi/phydm/phydm_debug.c +++ b/drivers/staging/rtlwifi/phydm/phydm_debug.c @@ -29,6 +29,7 @@ #include "mp_precomp.h" #include "phydm_precomp.h" +#include <linux/kernel.h> bool phydm_api_set_txagc(struct phy_dm_struct *, u32, enum odm_rf_radio_path, u8, bool); @@ -2107,8 +2108,7 @@ void phydm_cmd_parser(struct phy_dm_struct *dm, char input[][MAX_ARGV], /* Parsing Cmd ID */ if (input_num) { - phydm_ary_size = - sizeof(phy_dm_ary) / sizeof(struct phydm_command); + phydm_ary_size = ARRAY_SIZE(phy_dm_ary); for (i = 0; i < phydm_ary_size; i++) { if (strcmp(phy_dm_ary[i].name, input[0]) == 0) { id = phy_dm_ary[i].id; diff --git a/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_bb.c b/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_bb.c index 4e7946019fcb..29d19f2b300e 100644 --- a/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_bb.c +++ b/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_bb.c @@ -26,6 +26,7 @@ /*Image2HeaderVersion: 3.2*/ #include "../mp_precomp.h" #include "../phydm_precomp.h" +#include <linux/kernel.h> static bool check_positive(struct phy_dm_struct *dm, const u32 condition1, const u32 condition2, const u32 condition3, @@ -1350,7 +1351,6 @@ void odm_read_and_config_mp_8822b_agc_tab(struct phy_dm_struct *dm) u32 i = 0; u8 c_cond; bool is_matched = true, is_skipped = false; - u32 array_len = sizeof(array_mp_8822b_agc_tab) / sizeof(u32); u32 *array = array_mp_8822b_agc_tab; u32 v1 = 0, v2 = 0, pre_v1 = 0, pre_v2 = 0; @@ -1358,7 +1358,7 @@ void odm_read_and_config_mp_8822b_agc_tab(struct phy_dm_struct *dm) ODM_RT_TRACE(dm, ODM_COMP_INIT, "===> %s\n", __func__); - for (; (i + 1) < array_len; i = i + 2) { + for (; (i + 1) < ARRAY_SIZE(array_mp_8822b_agc_tab); i = i + 2) { v1 = array[i]; v2 = array[i + 1]; @@ -1843,7 +1843,6 @@ void odm_read_and_config_mp_8822b_phy_reg(struct phy_dm_struct *dm) u32 i = 0; u8 c_cond; bool is_matched = true, is_skipped = false; - u32 array_len = sizeof(array_mp_8822b_phy_reg) / sizeof(u32); u32 *array = array_mp_8822b_phy_reg; u32 v1 = 0, v2 = 0, pre_v1 = 0, pre_v2 = 0; @@ -1851,7 +1850,7 @@ void odm_read_and_config_mp_8822b_phy_reg(struct phy_dm_struct *dm) ODM_RT_TRACE(dm, ODM_COMP_INIT, "===> %s\n", __func__); - for (; (i + 1) < array_len; i = i + 2) { + for (; (i + 1) < ARRAY_SIZE(array_mp_8822b_phy_reg); i = i + 2) { v1 = array[i]; v2 = array[i + 1]; @@ -1947,7 +1946,6 @@ static u32 array_mp_8822b_phy_reg_pg[] = { void odm_read_and_config_mp_8822b_phy_reg_pg(struct phy_dm_struct *dm) { u32 i = 0; - u32 array_len = sizeof(array_mp_8822b_phy_reg_pg) / sizeof(u32); u32 *array = array_mp_8822b_phy_reg_pg; ODM_RT_TRACE(dm, ODM_COMP_INIT, @@ -1956,7 +1954,7 @@ void odm_read_and_config_mp_8822b_phy_reg_pg(struct phy_dm_struct *dm) dm->phy_reg_pg_version = 1; dm->phy_reg_pg_value_type = PHY_REG_PG_EXACT_VALUE; - for (i = 0; i < array_len; i += 6) { + for (i = 0; i < ARRAY_SIZE(array_mp_8822b_phy_reg_pg); i += 6) { u32 v1 = array[i]; u32 v2 = array[i + 1]; u32 v3 = array[i + 2]; diff --git a/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_mac.c b/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_mac.c index 1a9daed2e609..70924f002541 100644 --- a/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_mac.c +++ b/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_mac.c @@ -26,6 +26,7 @@ /*Image2HeaderVersion: 3.2*/ #include "../mp_precomp.h" #include "../phydm_precomp.h" +#include <linux/kernel.h> static bool check_positive(struct phy_dm_struct *dm, const u32 condition1, const u32 condition2, const u32 condition3, @@ -173,7 +174,6 @@ void odm_read_and_config_mp_8822b_mac_reg(struct phy_dm_struct *dm) u32 i = 0; u8 c_cond; bool is_matched = true, is_skipped = false; - u32 array_len = sizeof(array_mp_8822b_mac_reg) / sizeof(u32); u32 *array = array_mp_8822b_mac_reg; u32 v1 = 0, v2 = 0, pre_v1 = 0, pre_v2 = 0; @@ -181,7 +181,7 @@ void odm_read_and_config_mp_8822b_mac_reg(struct phy_dm_struct *dm) ODM_RT_TRACE(dm, ODM_COMP_INIT, "===> %s\n", __func__); - for (; (i + 1) < array_len; i = i + 2) { + for (; (i + 1) < ARRAY_SIZE(array_mp_8822b_mac_reg); i = i + 2) { v1 = array[i]; v2 = array[i + 1]; diff --git a/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.c b/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.c index 84cdc0644207..0ff3a9a712d6 100644 --- a/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.c +++ b/drivers/staging/rtlwifi/phydm/rtl8822b/halhwimg8822b_rf.c @@ -26,6 +26,7 @@ /*Image2HeaderVersion: 3.2*/ #include "../mp_precomp.h" #include "../phydm_precomp.h" +#include <linux/kernel.h> static bool check_positive(struct phy_dm_struct *dm, const u32 condition1, const u32 condition2, const u32 condition3, @@ -1346,7 +1347,6 @@ void odm_read_and_config_mp_8822b_radioa(struct phy_dm_struct *dm) u32 i = 0; u8 c_cond; bool is_matched = true, is_skipped = false; - u32 array_len = sizeof(array_mp_8822b_radioa) / sizeof(u32); u32 *array = array_mp_8822b_radioa; u32 v1 = 0, v2 = 0, pre_v1 = 0, pre_v2 = 0; @@ -1354,7 +1354,7 @@ void odm_read_and_config_mp_8822b_radioa(struct phy_dm_struct *dm) ODM_RT_TRACE(dm, ODM_COMP_INIT, "===> %s\n", __func__); - for (; (i + 1) < array_len; i = i + 2) { + for (; (i + 1) < ARRAY_SIZE(array_mp_8822b_radioa); i = i + 2) { v1 = array[i]; v2 = array[i + 1]; @@ -2506,7 +2506,6 @@ void odm_read_and_config_mp_8822b_radiob(struct phy_dm_struct *dm) u32 i = 0; u8 c_cond; bool is_matched = true, is_skipped = false; - u32 array_len = sizeof(array_mp_8822b_radiob) / sizeof(u32); u32 *array = array_mp_8822b_radiob; u32 v1 = 0, v2 = 0, pre_v1 = 0, pre_v2 = 0; @@ -2514,7 +2513,7 @@ void odm_read_and_config_mp_8822b_radiob(struct phy_dm_struct *dm) ODM_RT_TRACE(dm, ODM_COMP_INIT, "===> %s\n", __func__); - for (; (i + 1) < array_len; i = i + 2) { + for (; (i + 1) < ARRAY_SIZE(array_mp_8822b_radiob); i = i + 2) { v1 = array[i]; v2 = array[i + 1]; @@ -4239,13 +4238,12 @@ static const char *const array_mp_8822b_txpwr_lmt[] = { void odm_read_and_config_mp_8822b_txpwr_lmt(struct phy_dm_struct *dm) { u32 i = 0; - u32 array_len = sizeof(array_mp_8822b_txpwr_lmt) / sizeof(u8 *); u8 **array = (u8 **)array_mp_8822b_txpwr_lmt; ODM_RT_TRACE(dm, ODM_COMP_INIT, "===> %s\n", __func__); - for (i = 0; i < array_len; i += 7) { + for (i = 0; i < ARRAY_SIZE(array_mp_8822b_txpwr_lmt); i += 7) { u8 *regulation = array[i]; u8 *band = array[i + 1]; u8 *bandwidth = array[i + 2]; @@ -4723,13 +4721,12 @@ static const char *const array_mp_8822b_txpwr_lmt_type5[] = { void odm_read_and_config_mp_8822b_txpwr_lmt_type5(struct phy_dm_struct *dm) { u32 i = 0; - u32 array_len = sizeof(array_mp_8822b_txpwr_lmt_type5) / sizeof(u8 *); u8 **array = (u8 **)array_mp_8822b_txpwr_lmt_type5; ODM_RT_TRACE(dm, ODM_COMP_INIT, "===> odm_read_and_config_mp_8822b_txpwr_lmt_type5\n"); - for (i = 0; i < array_len; i += 7) { + for (i = 0; i < ARRAY_SIZE(array_mp_8822b_txpwr_lmt_type5); i += 7) { u8 *regulation = array[i]; u8 *band = array[i + 1]; u8 *bandwidth = array[i + 2]; |