Skip to content

Commit a59571a

Browse files
nrescobarkuba-moo
authored andcommitted
enic: Use macro instead of static const variables for array sizes
In enic_ethtool.c there is no need to use static const variables to store array sizes when a macro can be used instead. Signed-off-by: Nelson Escobar <neescoba@cisco.com> Signed-off-by: John Daley <johndale@cisco.com> Signed-off-by: Satish Kharat <satishkh@cisco.com> Link: https://patch.msgid.link/20240912005039.10797-2-neescoba@cisco.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 7bb50f3 commit a59571a

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

drivers/net/ethernet/cisco/enic/enic_ethtool.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ static const struct enic_stat enic_tx_stats[] = {
4646
ENIC_TX_STAT(tx_tso),
4747
};
4848

49+
#define NUM_ENIC_TX_STATS ARRAY_SIZE(enic_tx_stats)
50+
4951
static const struct enic_stat enic_rx_stats[] = {
5052
ENIC_RX_STAT(rx_frames_ok),
5153
ENIC_RX_STAT(rx_frames_total),
@@ -70,13 +72,13 @@ static const struct enic_stat enic_rx_stats[] = {
7072
ENIC_RX_STAT(rx_frames_to_max),
7173
};
7274

75+
#define NUM_ENIC_RX_STATS ARRAY_SIZE(enic_rx_stats)
76+
7377
static const struct enic_stat enic_gen_stats[] = {
7478
ENIC_GEN_STAT(dma_map_error),
7579
};
7680

77-
static const unsigned int enic_n_tx_stats = ARRAY_SIZE(enic_tx_stats);
78-
static const unsigned int enic_n_rx_stats = ARRAY_SIZE(enic_rx_stats);
79-
static const unsigned int enic_n_gen_stats = ARRAY_SIZE(enic_gen_stats);
81+
#define NUM_ENIC_GEN_STATS ARRAY_SIZE(enic_gen_stats)
8082

8183
static void enic_intr_coal_set_rx(struct enic *enic, u32 timer)
8284
{
@@ -145,15 +147,15 @@ static void enic_get_strings(struct net_device *netdev, u32 stringset,
145147

146148
switch (stringset) {
147149
case ETH_SS_STATS:
148-
for (i = 0; i < enic_n_tx_stats; i++) {
150+
for (i = 0; i < NUM_ENIC_TX_STATS; i++) {
149151
memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN);
150152
data += ETH_GSTRING_LEN;
151153
}
152-
for (i = 0; i < enic_n_rx_stats; i++) {
154+
for (i = 0; i < NUM_ENIC_RX_STATS; i++) {
153155
memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN);
154156
data += ETH_GSTRING_LEN;
155157
}
156-
for (i = 0; i < enic_n_gen_stats; i++) {
158+
for (i = 0; i < NUM_ENIC_GEN_STATS; i++) {
157159
memcpy(data, enic_gen_stats[i].name, ETH_GSTRING_LEN);
158160
data += ETH_GSTRING_LEN;
159161
}
@@ -244,7 +246,8 @@ static int enic_get_sset_count(struct net_device *netdev, int sset)
244246
{
245247
switch (sset) {
246248
case ETH_SS_STATS:
247-
return enic_n_tx_stats + enic_n_rx_stats + enic_n_gen_stats;
249+
return NUM_ENIC_TX_STATS + NUM_ENIC_RX_STATS +
250+
NUM_ENIC_GEN_STATS;
248251
default:
249252
return -EOPNOTSUPP;
250253
}
@@ -266,11 +269,11 @@ static void enic_get_ethtool_stats(struct net_device *netdev,
266269
if (err == -ENOMEM)
267270
return;
268271

269-
for (i = 0; i < enic_n_tx_stats; i++)
272+
for (i = 0; i < NUM_ENIC_TX_STATS; i++)
270273
*(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].index];
271-
for (i = 0; i < enic_n_rx_stats; i++)
274+
for (i = 0; i < NUM_ENIC_RX_STATS; i++)
272275
*(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].index];
273-
for (i = 0; i < enic_n_gen_stats; i++)
276+
for (i = 0; i < NUM_ENIC_GEN_STATS; i++)
274277
*(data++) = ((u64 *)&enic->gen_stats)[enic_gen_stats[i].index];
275278
}
276279

0 commit comments

Comments
 (0)