From: Simon Horman <horms@kernel.org>
To: Andrew Lunn <andrew@lunn.ch>,
Florian Fainelli <f.fainelli@gmail.com>,
Vladimir Oltean <olteanv@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Dan Carpenter <dan.carpenter@linaro.org>,
netdev@vger.kernel.org
Subject: [PATCH net-next RFC v2] net: dsa: mv88e6xxx: Correct check for empty list
Date: Sat, 27 Apr 2024 09:52:03 +0100 [thread overview]
Message-ID: <20240427-mv88e6xx-list_empty-v2-1-b7ce47c77bc7@kernel.org> (raw)
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, use list_first_entry() which does return NULL if the list is
empty.
Flagged by Smatch.
Compile tested only.
Signed-off-by: Simon Horman <horms@kernel.org>
---
Changes in v2:
- Use list_first_entry_or_null() instead of open-coding
a condition on list_empty().
Suggested by Dan Carpenter.
- Update commit message.
- Link to v1: https://lore.kernel.org/r/20240419-mv88e6xx-list_empty-v1-1-64fd6d1059a8@kernel.org
---
As discussed in v1, this is not being considered a fix
as it has been like this for a long time without any
reported problems.
---
drivers/net/dsa/mv88e6xxx/chip.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index f29ef72a2f1d..fc6e2e3ab0f0 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -131,8 +131,8 @@ struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
{
struct mv88e6xxx_mdio_bus *mdio_bus;
- mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
- list);
+ mdio_bus = list_first_entry_or_null(&chip->mdios,
+ struct mv88e6xxx_mdio_bus, list);
if (!mdio_bus)
return NULL;
next reply other threads:[~2024-04-27 8:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-27 8:52 Simon Horman [this message]
2024-04-27 8:53 ` [PATCH net-next RFC v2] net: dsa: mv88e6xxx: Correct check for empty list Simon Horman
2024-04-27 9:09 ` Dan Carpenter
2024-04-27 13:23 ` Andrew Lunn
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=20240427-mv88e6xx-list_empty-v2-1-b7ce47c77bc7@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 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).