netdev: ARRAY_SIZE() cleanups
Subsystems (3)
cover netdev: ARRAY_SIZE() cleanups
Hi,
these patches convert more cases of array size calculations to use the ARRAY_SIZE() macro.
First patch converts those of the form 'sizeof(arr) / ETH_GSTRING_LEN', second one some other mostly obvious cases, and the third applies to the almost dead sk98lin driver (which also removes a useless check AFAICS).
Alex
PATCH 1/3 netdev: use ARRAY_SIZE() instead of sizeof(array) / ETH_GSTRING_LEN
From: Alejandro Martinez Ruiz <[email protected]>
Date: Thu, 18 Oct 2007 10:00:15 +0200
Subject: [PATCH] netdev: use ARRAY_SIZE() instead of sizeof(array) / ETH_GSTRING_LEN
Using ARRAY_SIZE() on arrays of the form array[][K] makes it unnecessary to know the value of K when checking its size.
--- drivers/net/cassini.c | 2 +- drivers/net/e100.c | 4 ++-- drivers/net/e1000/e1000_ethtool.c | 2 +- drivers/net/e1000e/ethtool.c | 2 +- drivers/net/myri10ge/myri10ge.c | 2 +- drivers/net/netxen/netxen_nic_ethtool.c | 2 +- drivers/net/pcnet32.c | 2 +- drivers/net/s2io.c | 9 ++++----- drivers/net/tehuti.c | 8 +++----- 9 files changed, 15 insertions(+), 18 deletions(-)
drivers/net/cassini.c +1 -1
@@ -4419,7 +4419,7 @@ static struct { {"tx_fifo_errors"}, {"tx_packets"} }; -#define CAS_NUM_STAT_KEYS (sizeof(ethtool_cassini_statnames)/ETH_GSTRING_LEN) +#define CAS_NUM_STAT_KEYS ARRAY_SIZE(ethtool_cassini_statnames) static struct { const int offsets; /* neg. values for 2nd arg to cas_read_phy */
drivers/net/e100.c +2 -2
@@ -2372,7 +2372,7 @@ static const char e100_gstrings_test[][ETH_GSTRING_LEN] = {"Mac loopback (offline)" , "Phy loopback (offline)", }; -#define E100_TEST_LEN sizeof(e100_gstrings_test) / ETH_GSTRING_LEN +#define E100_TEST_LEN ARRAY_SIZE(e100_gstrings_test)static void e100_diag_test (struct net_device *netdev,struct ethtool_test *test,u64 *data)
@@ -2434,7 +2434,7 @@ static const char e100_gstrings_stats[][ETH_GSTRING_LEN] = { "rx_flow_control_unsupported", "tx_tco_packets", "rx_tco_packets", };#define E100_NET_STATS_LEN 21 -#define E100_STATS_LEN sizeof(e100_gstrings_stats) / ETH_GSTRING_LEN +#define E100_STATS_LEN ARRAY_SIZE(e100_gstrings_stats)static int e100_get_sset_count (struct net_device *netdev,int sset) {
drivers/net/e1000/e1000_ethtool.c +1 -1
@@ -113,7 +113,7 @@ static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {"Interrupt test (offline)" ,"Loopback test (offline)" , "Link test (on/offline)" }; -#define E1000_TEST_LEN sizeof(e1000_gstrings_test) / ETH_GSTRING_LEN +#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)static int e1000_get_settings (struct net_device *netdev,struct ethtool_cmd *ecmd)
drivers/net/e1000e/ethtool.c +1 -1
@@ -103,7 +103,7 @@ static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {"Interrupt test (offline)" ,"Loopback test (offline)" , "Link test (on/offline)" }; -#define E1000_TEST_LEN sizeof(e1000_gstrings_test) / ETH_GSTRING_LEN +#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)static int e1000_get_settings (struct net_device *netdev,struct ethtool_cmd *ecmd)
drivers/net/myri10ge/myri10ge.c +1 -1
@@ -1431,7 +1431,7 @@ static const char myri10ge_gstrings_stats[][ETH_GSTRING_LEN] = { };#define MYRI10GE_NET_STATS_LEN 21 -#define MYRI10GE_STATS_LEN sizeof(myri10ge_gstrings_stats) / ETH_GSTRING_LEN +#define MYRI10GE_STATS_LEN ARRAY_SIZE(myri10ge_gstrings_stats)static void myri10ge_get_strings (struct net_device *netdev,u32 stringset,u8 * data)
drivers/net/netxen/netxen_nic_ethtool.c +1 -1
@@ -86,7 +86,7 @@ static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = { "Link_Test_on_offline" }; -#define NETXEN_NIC_TEST_LEN sizeof(netxen_nic_gstrings_test) / ETH_GSTRING_LEN +#define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)#define NETXEN_NIC_REGS_COUNT 42#define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
drivers/net/pcnet32.c +1 -1
@@ -137,7 +137,7 @@ static const char pcnet32_gstrings_test[][ETH_GSTRING_LEN] = { "Loopback test (offline)" }; -#define PCNET32_TEST_LEN (sizeof(pcnet32_gstrings_test) / ETH_GSTRING_LEN) +#define PCNET32_TEST_LEN ARRAY_SIZE(pcnet32_gstrings_test)#define PCNET32_NUM_REGS 136
drivers/net/s2io.c +4 -5
@@ -335,10 +335,9 @@ static char ethtool_driver_stats_keys[][ETH_GSTRING_LEN] = { {"mc_err_cnt"} }; -#define S2IO_XENA_STAT_LEN sizeof(ethtool_xena_stats_keys)/ ETH_GSTRING_LEN -#define S2IO_ENHANCED_STAT_LEN sizeof(ethtool_enhanced_stats_keys)/ \ - ETH_GSTRING_LEN -#define S2IO_DRIVER_STAT_LEN sizeof(ethtool_driver_stats_keys)/ ETH_GSTRING_LEN +#define S2IO_XENA_STAT_LEN ARRAY_SIZE(ethtool_xena_stats_keys) +#define S2IO_ENHANCED_STAT_LEN ARRAY_SIZE(ethtool_enhanced_stats_keys) +#define S2IO_DRIVER_STAT_LEN ARRAY_SIZE(ethtool_driver_stats_keys)#define XFRAME_I_STAT_LEN (S2IO_XENA_STAT_LEN + S2IO_DRIVER_STAT_LEN )#define XFRAME_II_STAT_LEN (XFRAME_I_STAT_LEN + S2IO_ENHANCED_STAT_LEN )
@@ -346,7 +345,7 @@ static char ethtool_driver_stats_keys[][ETH_GSTRING_LEN] = {#define XFRAME_I_STAT_STRINGS_LEN ( XFRAME_I_STAT_LEN * ETH_GSTRING_LEN )#define XFRAME_II_STAT_STRINGS_LEN ( XFRAME_II_STAT_LEN * ETH_GSTRING_LEN ) -#define S2IO_TEST_LEN sizeof(s2io_gstrings) / ETH_GSTRING_LEN +#define S2IO_TEST_LEN ARRAY_SIZE(s2io_gstrings)#define S2IO_STRINGS_LEN S2IO_TEST_LEN * ETH_GSTRING_LEN#define S2IO_TIMER_CONF (timer, handle, arg, exp) \
drivers/net/tehuti.c +3 -5
@@ -2174,8 +2174,7 @@ bdx_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)strncat (drvinfo->bus_info,pci_name (priv->pdev),sizeof (drvinfo->bus_info)); - drvinfo->n_stats = ((priv->stats_flag) ? - (sizeof (bdx_stat_names) /ETH_GSTRING_LEN ) :0 ); + drvinfo->n_stats = ((priv->stats_flag) ?ARRAY_SIZE (bdx_stat_names) :0 ); drvinfo->testinfo_len =0 ; drvinfo->regdump_len =0 ; drvinfo->eedump_len =0 ;
@@ -2375,10 +2374,9 @@ static void bdx_get_strings(struct net_device *netdev, u32 stringset, u8 *data)static int bdx_get_stats_count (struct net_device *netdev) {struct bdx_priv *priv = netdev->priv; -BDX_ASSERT (sizeof (bdx_stat_names) /ETH_GSTRING_LEN +BDX_ASSERT (ARRAY_SIZE (bdx_stat_names) !=sizeof (struct bdx_stats ) /sizeof (u64)); -return ((priv->stats_flag) ? (sizeof (bdx_stat_names) /ETH_GSTRING_LEN ) - :0 ); +return ((priv->stats_flag) ?ARRAY_SIZE (bdx_stat_names) :0 ); }/*
Signature · 1 line
1.5.3.4
Re: [PATCH 1/3] netdev: use ARRAY_SIZE() instead of sizeof(array) / ETH_GSTRING_LEN
applied 1-3 to #upstream (2.6.25)
PATCH 2/3 netdev: ARRAY_SIZE() cleanups
In reply to Alejandro Martinez RuizFrom: Alejandro Martinez Ruiz <[email protected]>
Date: Thu, 18 Oct 2007 10:16:33 +0200
Subject: [PATCH] netdev: ARRAY_SIZE() cleanups
Convert array size calculations to use ARRAY_SIZE().
--- drivers/net/e1000e/ethtool.c | 3 +-- drivers/net/e1000e/phy.c | 3 +-- drivers/net/ixgbe/ixgbe_ethtool.c | 3 +-- drivers/net/tehuti.c | 2 +- drivers/net/tulip/de4x5.c | 2 +- drivers/net/wireless/ipw2100.c | 3 +-- drivers/net/wireless/libertas/11d.c | 24 +++++++----------------- drivers/net/wireless/libertas/wext.c | 11 +++-------- drivers/net/wireless/wavelan.c | 2 +- drivers/net/wireless/wavelan_cs.c | 4 ++-- 10 files changed, 19 insertions(+), 38 deletions(-)
drivers/net/e1000e/ethtool.c +1 -2
@@ -95,8 +95,7 @@ static const struct e1000_stats e1000_gstrings_stats[] = { { "tx_dma_failed", E1000_STAT(tx_dma_failed) }, }; -#define E1000_GLOBAL_STATS_LEN \ - sizeof(e1000_gstrings_stats) / sizeof(struct e1000_stats) +#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)static const char e1000_gstrings_test[][ETH_GSTRING_LEN ] = { "Register test (offline)", "Eeprom test (offline)",
drivers/net/e1000e/phy.c +1 -2
@@ -49,8 +49,7 @@ static const u16 e1000_igp_2_cable_length_table[] =100 ,105 ,109 ,113 ,116 ,119 ,122 ,124 ,104 ,109 ,114 ,118 ,121 , 124};#define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \ - (sizeof(e1000_igp_2_cable_length_table) / \ - sizeof(e1000_igp_2_cable_length_table[0])) + ARRAY_SIZE(e1000_igp_2_cable_length_table)/** * e1000e_check_reset_block_generic - Check if PHY reset is blocked
drivers/net/ixgbe/ixgbe_ethtool.c +1 -2
@@ -96,8 +96,7 @@ static struct ixgbe_stats ixgbe_gstrings_stats[] = { ((((struct ixgbe_adapter *)netdev->priv)->num_tx_queues + \ ((struct ixgbe_adapter *)netdev->priv)->num_rx_queues) * \ (sizeof(struct ixgbe_queue_stats) / sizeof(u64))) -#define IXGBE_GLOBAL_STATS_LEN \ - sizeof(ixgbe_gstrings_stats) / sizeof(struct ixgbe_stats) +#define IXGBE_GLOBAL_STATS_LEN ARRAY_SIZE(ixgbe_gstrings_stats)#define IXGBE_STATS_LEN (IXGBE_GLOBAL_STATS_LEN + IXGBE_QUEUE_STATS_LEN) static int ixgbe_get_settings(struct net_device *netdev,
drivers/net/tehuti.c +1 -1
@@ -621,7 +621,7 @@ err:static void __init bdx_firmware_endianess (void ) {int i; -for (i =0 ; i <sizeof (s_firmLoad) /sizeof (u32); i++) +for (i =0 ; i <ARRAY_SIZE (s_firmLoad); i++) s_firmLoad[i] =CPU_CHIP_SWAP32 (s_firmLoad[i]); }
drivers/net/tulip/de4x5.c +1 -1
@@ -4175,7 +4175,7 @@ de4x5_bad_srom(struct de4x5_private *lp) {int i, status =0 ; -for (i=0 ; i<sizeof (enet_det)/ETH_ALEN ; i++) { +for (i=0 ; i <ARRAY_SIZE (enet_det); i++) {if (!de4x5_strncmp ((char *)&lp->srom, (char *)&enet_det[i],3 ) && !de4x5_strncmp ((char *)&lp->srom+0x10 , (char *)&enet_det[i],3 )) {if (i ==0 ) {
drivers/net/wireless/ipw2100.c +1 -2
@@ -6582,8 +6582,7 @@ static const long ipw2100_frequencies[] = {2472 ,2484 }; -#define FREQ_COUNT (sizeof(ipw2100_frequencies) / \ - sizeof(ipw2100_frequencies[0])) +#define FREQ_COUNT ARRAY_SIZE(ipw2100_frequencies)static const long ipw2100_rates_11b[] = { 1000000,
drivers/net/wireless/libertas/11d.c +7 -17
@@ -46,13 +46,11 @@ static struct chan_freq_power channel_freq_power_UN_BG[] = {static u8 wlan_region_2_code (u8 * region) {u8 i; -u8 size =sizeof (region_code_mapping)/ -sizeof (struct region_code_mapping );for (i =0 ; region[i] && i <COUNTRY_CODE_LEN ; i++) region[i] =toupper (region[i]); -for (i =0 ; i < size; i++) { +for (i =0 ; i <ARRAY_SIZE (region_code_mapping); i++) {if (!memcmp (region, region_code_mapping[i].region,COUNTRY_CODE_LEN ))return (region_code_mapping[i].code);
@@ -65,9 +63,8 @@ static u8 wlan_region_2_code(u8 * region)static u8 *wlan_code_2_region (u8 code) {u8 i; -u8 size =sizeof (region_code_mapping) - /sizeof (struct region_code_mapping ); -for (i =0 ; i < size; i++) { + +for (i =0 ; i <ARRAY_SIZE (region_code_mapping); i++) {if (region_code_mapping[i].code == code)return (region_code_mapping[i].region); }
@@ -90,8 +87,7 @@ static u8 wlan_get_chan_11d(u8 band, u8 firstchan, u8 nrchan, u8 * chan)u8 cfp_no; cfp = channel_freq_power_UN_BG; - cfp_no =sizeof (channel_freq_power_UN_BG) / -sizeof (struct chan_freq_power ); + cfp_no =ARRAY_SIZE (channel_freq_power_UN_BG);for (i =0 ; i < cfp_no; i++) {if ((cfp + i)->channel == firstchan) {
@@ -141,16 +137,12 @@ static u8 wlan_channel_known_11d(u8 chan,u32 libertas_chan_2_freq (u8 chan,u8 band) {struct chan_freq_power *cf; -u16 cnt;u16 i;u32 freq =0 ; cf = channel_freq_power_UN_BG; - cnt = -sizeof (channel_freq_power_UN_BG) / -sizeof (struct chan_freq_power ); -for (i =0 ; i < cnt; i++) { +for (i =0 ; i <ARRAY_SIZE (channel_freq_power_UN_BG); i++) {if (chan == cf[i].channel) freq = cf[i].freq; }
@@ -664,8 +656,7 @@ int libertas_create_dnld_countryinfo_11d(wlan_private * priv)if (priv->adapter->enable11d) {/* update parsed_region_chan_11; dnld domaininf to FW */ -for (j =0 ; j <sizeof (adapter->region_channel) / -sizeof (adapter->region_channel[0 ]); j++) { +for (j =0 ; j <ARRAY_SIZE (adapter->region_channel); j++) { region_chan = &adapter->region_channel[j]; lbs_deb_11d("%d region_chan->band %d\n", j,
@@ -679,8 +670,7 @@ int libertas_create_dnld_countryinfo_11d(wlan_private * priv)break ; } -if (j >=sizeof (adapter->region_channel) / -sizeof (adapter->region_channel[0 ])) { +if (j >=ARRAY_SIZE (adapter->region_channel)) {lbs_deb_11d ("region_chan not found, band %d\n" , adapter->curbssparams.band); ret =-1 ;
drivers/net/wireless/libertas/wext.c +3 -8
@@ -34,11 +34,9 @@ struct chan_freq_power *libertas_find_cfp_by_band_and_channel(wlan_adapter * ada {struct chan_freq_power *cfp =NULL ;struct region_channel *rc; -int count =sizeof (adapter->region_channel) / -sizeof (adapter->region_channel[0 ]);int i, j; -for (j =0 ; !cfp && (j < count); j++) { +for (j =0 ; !cfp && (j <ARRAY_SIZE (adapter->region_channel)); j++) { rc = &adapter->region_channel[j];if (adapter->enable11d)
@@ -75,11 +73,9 @@ static struct chan_freq_power *find_cfp_by_band_and_freq(wlan_adapter * adapter, {struct chan_freq_power *cfp =NULL ;struct region_channel *rc; -int count =sizeof (adapter->region_channel) / -sizeof (adapter->region_channel[0 ]);int i, j; -for (j =0 ; !cfp && (j < count); j++) { +for (j =0 ; !cfp && (j <ARRAY_SIZE (adapter->region_channel)); j++) { rc = &adapter->region_channel[j];if (adapter->enable11d)
@@ -606,8 +602,7 @@ static int wlan_get_range(struct net_device *dev, struct iw_request_info *info, }if (!flag) {for (j =0 ; (range->num_frequency <IW_MAX_FREQUENCIES ) - && (j <sizeof (adapter->region_channel) - /sizeof (adapter->region_channel[0 ])); j++) { + && (j <ARRAY_SIZE (adapter->region_channel)); j++) { cfp = adapter->region_channel[j].CFP; for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES) && adapter->region_channel[j].valid
drivers/net/wireless/wavelan.c +1 -1
@@ -3740,7 +3740,7 @@ static int wv_check_ioaddr(unsigned long ioaddr, u8 * mac)* non-NCR/AT&T/Lucent ISA card. See wavelan.p.h for detail on * how to configure your card. */ -for (i =0 ; i < (sizeof (MAC_ADDRESSES ) /sizeof (char ) /3 ); i++) +for (i =0 ; i <ARRAY_SIZE (MAC_ADDRESSES ); i++)if ((mac[0 ] ==MAC_ADDRESSES [i][0 ]) && (mac[1 ] ==MAC_ADDRESSES [i][1 ]) && (mac[2 ] ==MAC_ADDRESSES [i][2 ]))
drivers/net/wireless/wavelan_cs.c +2 -2
@@ -3223,14 +3223,14 @@ wv_mmc_init(struct net_device * dev)* non-NCR/AT&T/Lucent PCMCIA cards, see wavelan_cs.h for detail on * how to configure your card... */ -for (i =0 ; i < (sizeof (MAC_ADDRESSES ) /sizeof (char ) /3 ); i++) +for (i =0 ; i <ARRAY_SIZE (MAC_ADDRESSES ); i++)if ((psa.psa_univ_mac_addr[0 ] ==MAC_ADDRESSES [i][0 ]) && (psa.psa_univ_mac_addr[1 ] ==MAC_ADDRESSES [i][1 ]) && (psa.psa_univ_mac_addr[2 ] ==MAC_ADDRESSES [i][2 ]))break ;/* If we have not found it... */ -if (i == (sizeof (MAC_ADDRESSES ) /sizeof (char ) /3 )) +if (i ==ARRAY_SIZE (MAC_ADDRESSES )) {#ifdef DEBUG_CONFIG_ERRORS printk(KERN_WARNING "%s: wv_mmc_init(): Invalid MAC address: %02X:%02X:%02X:...\n",
Signature · 1 line
1.5.3.4
PATCH 3/3 sk98lin: kill bogus check and convert to use ARRAY_SIZE()
In reply to Alejandro Martinez RuizFrom: Alejandro Martinez Ruiz <[email protected]>
Date: Thu, 18 Oct 2007 10:22:02 +0200
Subject: [PATCH] sk98lin: kill bogus check and convert to use ARRAY_SIZE()
This converts uses of ARRAY_SIZE(), and while at it also kills unreachable code as far as I can say. I can't tell what was the author trying to do with the following check. First we have:
PNMI_STATIC const SK_PNMI_STATADDR
StatAddr[SK_PNMI_MAX_IDX][SK_PNMI_MAC_TYPES];
and then a check goes like this:
if (SK_PNMI_MAX_IDX !=
(sizeof(StatAddr) / (sizeof(SK_PNMI_STATADDR) * SK_PNMI_MAC_TYPES)))
with the second line being just ARRAY_SIZE(StatAddr), which will always return SK_PNMI_MAX_IDX, rendering the check useless.
--- drivers/net/sk98lin/skgemib.c | 2 +- drivers/net/sk98lin/skgepnmi.c | 12 ------------ drivers/net/sk98lin/skgesirq.c | 2 +- 3 files changed, 2 insertions(+), 14 deletions(-)
drivers/net/sk98lin/skgemib.c +1 -1
@@ -82,7 +82,7 @@ PNMI_STATIC int DiagActions(SK_AC *pAC, SK_IOC IoC, int action, SK_U32 Id,/* defines *******************************************************************/ -#define ID_TABLE_SIZE (sizeof(IdTable)/sizeof(IdTable[0])) +#define ID_TABLE_SIZE ARRAY_SIZE(IdTable)/* global variables **********************************************************/
drivers/net/sk98lin/skgepnmi.c +0 -12
@@ -388,18 +388,6 @@ int Level) /* Initialization level */ SK_PNMI_CNT_NO, SK_PNMI_MAX_IDX)); } -if (SK_PNMI_MAX_IDX != - (sizeof (StatAddr) / (sizeof (SK_PNMI_STATADDR ) *SK_PNMI_MAC_TYPES ))) { - -SK_ERR_LOG (pAC,SK_ERRCL_SW ,SK_PNMI_ERR050 ,SK_PNMI_ERR050MSG ); - -SK_DBG_MSG (pAC,SK_DBGMOD_PNMI ,SK_DBGCAT_INIT |SK_DBGCAT_FATAL , - ("StatAddr table size (%d) differs from " -"SK_PNMI_MAX_IDX (%d)\n" , - (sizeof (StatAddr) / - (sizeof (SK_PNMI_STATADDR ) *SK_PNMI_MAC_TYPES )), -SK_PNMI_MAX_IDX )); - }#endif /* SK_PNMI_CHECK */ break ;
drivers/net/sk98lin/skgesirq.c +1 -1
@@ -892,7 +892,7 @@ int Port) /* Which port should be checked */*/ RxCts =0 ; -for (i =0 ; i <sizeof (SkGeRxRegs)/sizeof (SkGeRxRegs[0 ]); i++) { +for (i =0 ; i <ARRAY_SIZE (SkGeRxRegs); i++) { (void )SkXmMacStatistic (pAC, IoC, Port, SkGeRxRegs[i], &RxTmp);
Signature · 1 line
1.5.3.4