linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bug report] net/mlx5e: Allocate per-channel stats dynamically at first usage
@ 2022-01-06 11:45 Dan Carpenter
  0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2022-01-06 11:45 UTC (permalink / raw)
  To: lkayal; +Cc: linux-rdma

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-06 11:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-06 11:45 [bug report] net/mlx5e: Allocate per-channel stats dynamically at first usage Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).