enic: Use macro instead of static const variables for array sizes
authorNelson Escobar <neescoba@cisco.com>
Thu, 12 Sep 2024 00:50:36 +0000 (17:50 -0700)
committerJakub Kicinski <kuba@kernel.org>
Sat, 14 Sep 2024 04:17:11 +0000 (21:17 -0700)
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>
drivers/net/ethernet/cisco/enic/enic_ethtool.c

index 31685ee304c6ff5c1729cf11f9156443a5e08529..e49543d97a83b9fef32356f920b7cadc2c893fa3 100644 (file)
@@ -46,6 +46,8 @@ static const struct enic_stat enic_tx_stats[] = {
        ENIC_TX_STAT(tx_tso),
 };
 
+#define NUM_ENIC_TX_STATS      ARRAY_SIZE(enic_tx_stats)
+
 static const struct enic_stat enic_rx_stats[] = {
        ENIC_RX_STAT(rx_frames_ok),
        ENIC_RX_STAT(rx_frames_total),
@@ -70,13 +72,13 @@ static const struct enic_stat enic_rx_stats[] = {
        ENIC_RX_STAT(rx_frames_to_max),
 };
 
+#define NUM_ENIC_RX_STATS      ARRAY_SIZE(enic_rx_stats)
+
 static const struct enic_stat enic_gen_stats[] = {
        ENIC_GEN_STAT(dma_map_error),
 };
 
-static const unsigned int enic_n_tx_stats = ARRAY_SIZE(enic_tx_stats);
-static const unsigned int enic_n_rx_stats = ARRAY_SIZE(enic_rx_stats);
-static const unsigned int enic_n_gen_stats = ARRAY_SIZE(enic_gen_stats);
+#define NUM_ENIC_GEN_STATS     ARRAY_SIZE(enic_gen_stats)
 
 static void enic_intr_coal_set_rx(struct enic *enic, u32 timer)
 {
@@ -145,15 +147,15 @@ static void enic_get_strings(struct net_device *netdev, u32 stringset,
 
        switch (stringset) {
        case ETH_SS_STATS:
-               for (i = 0; i < enic_n_tx_stats; i++) {
+               for (i = 0; i < NUM_ENIC_TX_STATS; i++) {
                        memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN);
                        data += ETH_GSTRING_LEN;
                }
-               for (i = 0; i < enic_n_rx_stats; i++) {
+               for (i = 0; i < NUM_ENIC_RX_STATS; i++) {
                        memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN);
                        data += ETH_GSTRING_LEN;
                }
-               for (i = 0; i < enic_n_gen_stats; i++) {
+               for (i = 0; i < NUM_ENIC_GEN_STATS; i++) {
                        memcpy(data, enic_gen_stats[i].name, ETH_GSTRING_LEN);
                        data += ETH_GSTRING_LEN;
                }
@@ -244,7 +246,8 @@ static int enic_get_sset_count(struct net_device *netdev, int sset)
 {
        switch (sset) {
        case ETH_SS_STATS:
-               return enic_n_tx_stats + enic_n_rx_stats + enic_n_gen_stats;
+               return NUM_ENIC_TX_STATS + NUM_ENIC_RX_STATS +
+                       NUM_ENIC_GEN_STATS;
        default:
                return -EOPNOTSUPP;
        }
@@ -266,11 +269,11 @@ static void enic_get_ethtool_stats(struct net_device *netdev,
        if (err == -ENOMEM)
                return;
 
-       for (i = 0; i < enic_n_tx_stats; i++)
+       for (i = 0; i < NUM_ENIC_TX_STATS; i++)
                *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].index];
-       for (i = 0; i < enic_n_rx_stats; i++)
+       for (i = 0; i < NUM_ENIC_RX_STATS; i++)
                *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].index];
-       for (i = 0; i < enic_n_gen_stats; i++)
+       for (i = 0; i < NUM_ENIC_GEN_STATS; i++)
                *(data++) = ((u64 *)&enic->gen_stats)[enic_gen_stats[i].index];
 }