net/mlx5: cleanup allocation of ethtool stats
authorThierry Herbelot <thierry.herbelot@6wind.com>
Fri, 17 Nov 2017 13:51:34 +0000 (14:51 +0100)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 16 Jan 2018 17:47:49 +0000 (18:47 +0100)
Simplify the computation for the needed size:
- exact size for the structure header,
- exact size for a number of 64-bit counters.

Fixes: a4193ae3bc4f ("net/mlx5: support extended statistics")
Cc: stable@dpdk.org
Signed-off-by: Thierry Herbelot <thierry.herbelot@6wind.com>
Acked-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
drivers/net/mlx5/mlx5_stats.c

index 5e225d3..2427585 100644 (file)
@@ -143,11 +143,9 @@ priv_read_dev_counters(struct priv *priv, uint64_t *stats)
        struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
        unsigned int i;
        struct ifreq ifr;
-       unsigned int stats_sz = (xstats_ctrl->stats_n * sizeof(uint64_t)) +
-                                sizeof(struct ethtool_stats);
-       struct ethtool_stats et_stats[(stats_sz + (
-                                     sizeof(struct ethtool_stats) - 1)) /
-                                     sizeof(struct ethtool_stats)];
+       unsigned int stats_sz = xstats_ctrl->stats_n * sizeof(uint64_t);
+       unsigned char et_stat_buf[sizeof(struct ethtool_stats) + stats_sz];
+       struct ethtool_stats *et_stats = (struct ethtool_stats *)et_stat_buf;
 
        et_stats->cmd = ETHTOOL_GSTATS;
        et_stats->n_stats = xstats_ctrl->stats_n;