Skip to content

Commit

Permalink
netdev: use ARRAY_SIZE() instead of sizeof(array) / ETH_GSTRING_LEN
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Alejandro Martinez Ruiz authored and David S. Miller committed Jan 28, 2008
1 parent f59d978 commit 4c3616c
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion drivers/net/cassini.c
Original file line number Diff line number Diff line change
Expand Up @@ -4394,7 +4394,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 */
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/e100.c
Original file line number Diff line number Diff line change
Expand Up @@ -2369,7 +2369,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)
Expand Down Expand Up @@ -2431,7 +2431,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)
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/e1000/e1000_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,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)
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/e1000e/ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/myri10ge/myri10ge.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/netxen/netxen_nic_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/pcnet32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 4 additions & 5 deletions drivers/net/s2io.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,18 +335,17 @@ 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 )

#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) \
Expand Down
8 changes: 3 additions & 5 deletions drivers/net/tehuti.c
Original file line number Diff line number Diff line change
Expand Up @@ -2174,8 +2174,7 @@ bdx_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
strlcat(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;
Expand Down Expand Up @@ -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);
}

/*
Expand Down

0 comments on commit 4c3616c

Please sign in to comment.