All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: horatiu.vultur@microchip.com
Cc: kernel-janitors@vger.kernel.org
Subject: [bug report] net: ocelot: Extend MRP
Date: Thu, 18 Mar 2021 15:07:32 +0300	[thread overview]
Message-ID: <YFNChN/C6JwVAV2t@mwanda> (raw)

Hello Horatiu Vultur,

This is a semi-automatic email about new static checker warnings.

The patch 7c588c3e96e9: "net: ocelot: Extend MRP" from Mar 16, 2021,
leads to the following Smatch complaint:

    drivers/net/ethernet/mscc/ocelot_mrp.c:180 ocelot_mrp_del()
    error: we previously assumed 'ocelot_port' could be null (see line 173)

drivers/net/ethernet/mscc/ocelot_mrp.c
   153  int ocelot_mrp_del(struct ocelot *ocelot, int port,
   154                     const struct switchdev_obj_mrp *mrp)
   155  {
   156          struct ocelot_port *ocelot_port = ocelot->ports[port];
   157          int i;
   158  
   159          if (!ocelot_port)
   160                  return -EOPNOTSUPP;
   161  
   162          if (ocelot_port->mrp_ring_id != mrp->ring_id)
   163                  return 0;
   164  
   165          ocelot_mrp_del_vcap(ocelot, port);
   166          ocelot_mrp_del_vcap(ocelot, port + ocelot->num_phys_ports);
   167  
   168          ocelot_port->mrp_ring_id = 0;
   169  
   170          for (i = 0; i < ocelot->num_phys_ports; ++i) {

This loop tries to verify that all the ports have ring_id == 0 otherwise
we return.  It's slightly confusing why this matters.

   171                  ocelot_port = ocelot->ports[i];
   172	
   173			if (!ocelot_port)
                             ^^^^^^^^^^^
Assume the last element of the array is NULL

   174				continue;
   175	
   176			if (ocelot_port->mrp_ring_id != 0)
   177				goto out;

This would be more clear if instead of a "goto out;" it just did a
direct "return 0;"

   178		}
   179	
   180		ocelot_mrp_del_mac(ocelot, ocelot_port);

We delete the last mac address of all the ring_ids are zero but if the
last port is zero it will crash.

   181	out:
   182		return 0;

regards,
dan carpenter

             reply	other threads:[~2021-03-18 12:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18 12:07 Dan Carpenter [this message]
2021-03-18 12:11 ` [bug report] net: ocelot: Extend MRP Dan Carpenter
2021-03-18 18:57   ` Horatiu Vultur

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=YFNChN/C6JwVAV2t@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=horatiu.vultur@microchip.com \
    --cc=kernel-janitors@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.