[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240419-mv88e6xx-list_empty-v1-1-64fd6d1059a8@kernel.org>
Date: Fri, 19 Apr 2024 13:17:48 +0100
From: Simon Horman <horms@...nel.org>
To: Andrew Lunn <andrew@...n.ch>, Florian Fainelli <f.fainelli@...il.com>,
Vladimir Oltean <olteanv@...il.com>
Cc: "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>, Dan Carpenter <dan.carpenter@...aro.org>,
netdev@...r.kernel.org
Subject: [PATCH net-next RFC] net: dsa: mv88e6xxx: Correct check for empty
list
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@...nel.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;
return mdio_bus->bus;
}
---
drivers/net/dsa/mv88e6xxx/chip.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
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;
return mdio_bus->bus;
}
Powered by blists - more mailing lists