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

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.

Signed-off-by: Alejandro Martinez Ruiz <alex@flawedcode.org>
Signed-off-by: Jeff Garzik <jeff@garzik.org>

authored by

Alejandro Martinez Ruiz and committed by
David S. Miller
4c3616cd f59d9782

+15 -18
+1 -1
drivers/net/cassini.c
··· 4394 4394 {"tx_fifo_errors"}, 4395 4395 {"tx_packets"} 4396 4396 }; 4397 - #define CAS_NUM_STAT_KEYS (sizeof(ethtool_cassini_statnames)/ETH_GSTRING_LEN) 4397 + #define CAS_NUM_STAT_KEYS ARRAY_SIZE(ethtool_cassini_statnames) 4398 4398 4399 4399 static struct { 4400 4400 const int offsets; /* neg. values for 2nd arg to cas_read_phy */
+2 -2
drivers/net/e100.c
··· 2369 2369 "Mac loopback (offline)", 2370 2370 "Phy loopback (offline)", 2371 2371 }; 2372 - #define E100_TEST_LEN sizeof(e100_gstrings_test) / ETH_GSTRING_LEN 2372 + #define E100_TEST_LEN ARRAY_SIZE(e100_gstrings_test) 2373 2373 2374 2374 static void e100_diag_test(struct net_device *netdev, 2375 2375 struct ethtool_test *test, u64 *data) ··· 2431 2431 "rx_flow_control_unsupported", "tx_tco_packets", "rx_tco_packets", 2432 2432 }; 2433 2433 #define E100_NET_STATS_LEN 21 2434 - #define E100_STATS_LEN sizeof(e100_gstrings_stats) / ETH_GSTRING_LEN 2434 + #define E100_STATS_LEN ARRAY_SIZE(e100_gstrings_stats) 2435 2435 2436 2436 static int e100_get_sset_count(struct net_device *netdev, int sset) 2437 2437 {
+1 -1
drivers/net/e1000/e1000_ethtool.c
··· 110 110 "Interrupt test (offline)", "Loopback test (offline)", 111 111 "Link test (on/offline)" 112 112 }; 113 - #define E1000_TEST_LEN sizeof(e1000_gstrings_test) / ETH_GSTRING_LEN 113 + #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test) 114 114 115 115 static int 116 116 e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
+1 -1
drivers/net/e1000e/ethtool.c
··· 103 103 "Interrupt test (offline)", "Loopback test (offline)", 104 104 "Link test (on/offline)" 105 105 }; 106 - #define E1000_TEST_LEN sizeof(e1000_gstrings_test) / ETH_GSTRING_LEN 106 + #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test) 107 107 108 108 static int e1000_get_settings(struct net_device *netdev, 109 109 struct ethtool_cmd *ecmd)
+1 -1
drivers/net/myri10ge/myri10ge.c
··· 1431 1431 }; 1432 1432 1433 1433 #define MYRI10GE_NET_STATS_LEN 21 1434 - #define MYRI10GE_STATS_LEN sizeof(myri10ge_gstrings_stats) / ETH_GSTRING_LEN 1434 + #define MYRI10GE_STATS_LEN ARRAY_SIZE(myri10ge_gstrings_stats) 1435 1435 1436 1436 static void 1437 1437 myri10ge_get_strings(struct net_device *netdev, u32 stringset, u8 * data)
+1 -1
drivers/net/netxen/netxen_nic_ethtool.c
··· 86 86 "Link_Test_on_offline" 87 87 }; 88 88 89 - #define NETXEN_NIC_TEST_LEN sizeof(netxen_nic_gstrings_test) / ETH_GSTRING_LEN 89 + #define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test) 90 90 91 91 #define NETXEN_NIC_REGS_COUNT 42 92 92 #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
+1 -1
drivers/net/pcnet32.c
··· 137 137 "Loopback test (offline)" 138 138 }; 139 139 140 - #define PCNET32_TEST_LEN (sizeof(pcnet32_gstrings_test) / ETH_GSTRING_LEN) 140 + #define PCNET32_TEST_LEN ARRAY_SIZE(pcnet32_gstrings_test) 141 141 142 142 #define PCNET32_NUM_REGS 136 143 143
+4 -5
drivers/net/s2io.c
··· 335 335 {"mc_err_cnt"} 336 336 }; 337 337 338 - #define S2IO_XENA_STAT_LEN sizeof(ethtool_xena_stats_keys)/ ETH_GSTRING_LEN 339 - #define S2IO_ENHANCED_STAT_LEN sizeof(ethtool_enhanced_stats_keys)/ \ 340 - ETH_GSTRING_LEN 341 - #define S2IO_DRIVER_STAT_LEN sizeof(ethtool_driver_stats_keys)/ ETH_GSTRING_LEN 338 + #define S2IO_XENA_STAT_LEN ARRAY_SIZE(ethtool_xena_stats_keys) 339 + #define S2IO_ENHANCED_STAT_LEN ARRAY_SIZE(ethtool_enhanced_stats_keys) 340 + #define S2IO_DRIVER_STAT_LEN ARRAY_SIZE(ethtool_driver_stats_keys) 342 341 343 342 #define XFRAME_I_STAT_LEN (S2IO_XENA_STAT_LEN + S2IO_DRIVER_STAT_LEN ) 344 343 #define XFRAME_II_STAT_LEN (XFRAME_I_STAT_LEN + S2IO_ENHANCED_STAT_LEN ) ··· 345 346 #define XFRAME_I_STAT_STRINGS_LEN ( XFRAME_I_STAT_LEN * ETH_GSTRING_LEN ) 346 347 #define XFRAME_II_STAT_STRINGS_LEN ( XFRAME_II_STAT_LEN * ETH_GSTRING_LEN ) 347 348 348 - #define S2IO_TEST_LEN sizeof(s2io_gstrings) / ETH_GSTRING_LEN 349 + #define S2IO_TEST_LEN ARRAY_SIZE(s2io_gstrings) 349 350 #define S2IO_STRINGS_LEN S2IO_TEST_LEN * ETH_GSTRING_LEN 350 351 351 352 #define S2IO_TIMER_CONF(timer, handle, arg, exp) \
+3 -5
drivers/net/tehuti.c
··· 2174 2174 strlcat(drvinfo->bus_info, pci_name(priv->pdev), 2175 2175 sizeof(drvinfo->bus_info)); 2176 2176 2177 - drvinfo->n_stats = ((priv->stats_flag) ? 2178 - (sizeof(bdx_stat_names) / ETH_GSTRING_LEN) : 0); 2177 + drvinfo->n_stats = ((priv->stats_flag) ? ARRAY_SIZE(bdx_stat_names) : 0); 2179 2178 drvinfo->testinfo_len = 0; 2180 2179 drvinfo->regdump_len = 0; 2181 2180 drvinfo->eedump_len = 0; ··· 2374 2375 static int bdx_get_stats_count(struct net_device *netdev) 2375 2376 { 2376 2377 struct bdx_priv *priv = netdev->priv; 2377 - BDX_ASSERT(sizeof(bdx_stat_names) / ETH_GSTRING_LEN 2378 + BDX_ASSERT(ARRAY_SIZE(bdx_stat_names) 2378 2379 != sizeof(struct bdx_stats) / sizeof(u64)); 2379 - return ((priv->stats_flag) ? (sizeof(bdx_stat_names) / ETH_GSTRING_LEN) 2380 - : 0); 2380 + return ((priv->stats_flag) ? ARRAY_SIZE(bdx_stat_names) : 0); 2381 2381 } 2382 2382 2383 2383 /*