[bug report] net/mlx5e: Allocate per-channel stats dynamically at first usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Lama Kayal,

The patch fa691d0c9c08: "net/mlx5e: Allocate per-channel stats
dynamically at first usage" from Sep 22, 2021, leads to the following
Smatch static checker warning:

	drivers/net/ethernet/mellanox/mlx5/core/en_main.c:2205 mlx5e_channel_stats_alloc()
	warn: array off by one? 'priv->channel_stats[ix]'

This is from an unpublishable check (too many false positives by design).

drivers/net/ethernet/mellanox/mlx5/core/en_main.c
    2197 static int mlx5e_channel_stats_alloc(struct mlx5e_priv *priv, int ix, int cpu)
    2198 {
    2199         if (ix > priv->stats_nch)  {

I don't think this check makes sense.  As far as I can see "ix" is
always == priv->stats_nch which is set on the last line of the the
function.  Probably the check should be:

	if (ix >= priv->max_nch) {

    2200                 netdev_warn(priv->netdev, "Unexpected channel stats index %d > %d\n", ix,
    2201                             priv->stats_nch);
    2202                 return -EINVAL;
    2203         }
    2204 
--> 2205         if (priv->channel_stats[ix])
    2206                 return 0;
    2207 
    2208         /* Asymmetric dynamic memory allocation.
    2209          * Freed in mlx5e_priv_arrays_free, not on channel closure.
    2210          */
    2211         mlx5e_dbg(DRV, priv, "Creating channel stats %d\n", ix);
    2212         priv->channel_stats[ix] = kvzalloc_node(sizeof(**priv->channel_stats),
    2213                                                 GFP_KERNEL, cpu_to_node(cpu));
    2214         if (!priv->channel_stats[ix])
    2215                 return -ENOMEM;
    2216         priv->stats_nch++;
    2217 
    2218         return 0;
    2219 }

regards,
dan carpenter



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux