Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: lkayal@nvidia.com
Cc: linux-rdma@vger.kernel.org
Subject: [bug report] net/mlx5e: Allocate per-channel stats dynamically at first usage
Date: Thu, 6 Jan 2022 14:45:29 +0300	[thread overview]
Message-ID: <20220106114529.GA28590@kili> (raw)

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

                 reply	other threads:[~2022-01-06 11:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220106114529.GA28590@kili \
    --to=dan.carpenter@oracle.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=lkayal@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox