From: Simon Horman <horms@kernel.org>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Andrew Lunn <andrew@lunn.ch>,
Florian Fainelli <f.fainelli@gmail.com>,
Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org
Subject: Re: [PATCH net-next RFC] net: dsa: mv88e6xxx: Correct check for empty list
Date: Tue, 23 Apr 2024 20:52:54 +0100 [thread overview]
Message-ID: <20240423195254.GA42092@kernel.org> (raw)
In-Reply-To: <d667834a-476b-4f33-9c94-10b3672b6edb@moroto.mountain>
On Mon, Apr 22, 2024 at 01:40:01PM +0300, Dan Carpenter wrote:
> On Fri, Apr 19, 2024 at 01:17:48PM +0100, Simon Horman wrote:
> > Since commit a3c53be55c95 ("net: dsa: mv88e6xxx: Support multiple MDIO
> > busses") mv88e6xxx_default_mdio_bus() has checked that the
> > return value of list_first_entry() is non-NULL. This appears to be
> > intended to guard against the list chip->mdios being empty.
> > However, it is not the correct check as the implementation of
> > list_first_entry is not designed to return NULL for empty lists.
> >
> > Instead check directly if the list is empty.
> >
> > Flagged by Smatch
> >
> > Signed-off-by: Simon Horman <horms@kernel.org>
> > ---
> > I'm unsure if this should be considered a fix: it's been around since
> > v4.11 and the patch is dated January 2017. Perhaps an empty list simply
> > cannot occur. If so, the function could be simplified by not checking
> > for an empty list. And, if mdio_bus->bus, then perhaps caller may be
> > simplified not to check for an error condition.
> >
> > It is because I am unsure that I have marked this as an RFC.
> >
> > diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
> > index e950a634a3c7..a236c9fe6a74 100644
> > --- a/drivers/net/dsa/mv88e6xxx/chip.c
> > +++ b/drivers/net/dsa/mv88e6xxx/chip.c
> > @@ -131,10 +131,11 @@ struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
> > {
> > struct mv88e6xxx_mdio_bus *mdio_bus;
> >
> > + if (list_empty(&chip->mdios))
> > + return NULL;
> > +
> > mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
> > list);
> > - if (!mdio_bus)
> > - return NULL;
>
> The other option here would have been to use list_first_entry_or_null().
Thanks, I guess that is nicer than the open-coded approach I suggested.
prev parent reply other threads:[~2024-04-23 19:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-19 12:17 [PATCH net-next RFC] net: dsa: mv88e6xxx: Correct check for empty list Simon Horman
2024-04-19 15:44 ` Andrew Lunn
2024-04-22 10:40 ` Dan Carpenter
2024-04-23 19:52 ` Simon Horman [this message]
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=20240423195254.GA42092@kernel.org \
--to=horms@kernel.org \
--cc=andrew@lunn.ch \
--cc=dan.carpenter@linaro.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.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 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.