Skip to contentSkip to conversation

net: mdiobus: get rid of a BUG_ON()

PATCH Superseded Dan Carpenter 4 participants 5 messages May 15, 2021 – May 17, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: mdiobus: get rid of a BUG_ON()

We spotted a bug recently during a review where a driver was unregistering a bus that wasn't registered, which would trigger this BUG_ON(). Let's handle that situation more gracefully, and just print a warning and return.

---
 drivers/net/phy/mdio_bus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/phy/mdio_bus.c +2 -1
index dadf75ff3ab9..6045ad3def12 100644
@@ -607,7 +607,8 @@ void mdiobus_unregister(struct mii_bus *bus)
 	struct mdio_device *mdiodev;
 	int i;
 
-	BUG_ON(bus->state != MDIOBUS_REGISTERED);
+	if (WARN_ON_ONCE(bus->state != MDIOBUS_REGISTERED))
+		return;
 	bus->state = MDIOBUS_UNREGISTERED;
 
 	for (i = 0; i < PHY_MAX_ADDR; i++) {
Signature · 1 line
2.30.2
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Dan Carpenter

We spotted a bug recently during a review where a driver was unregistering a bus that wasn't registered, which would trigger this BUG_ON(). Let's handle that situation more gracefully, and just print a warning and return.

This probably ought to be updated to:

now please.

Quoted 1 line
Quoted 22 lines
---
 drivers/net/phy/mdio_bus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/phy/mdio_bus.c +2 -1
index dadf75ff3ab9..6045ad3def12 100644
@@ -607,7 +607,8 @@ void mdiobus_unregister(struct mii_bus *bus)
 	struct mdio_device *mdiodev;
 	int i;
 
-	BUG_ON(bus->state != MDIOBUS_REGISTERED);
+	if (WARN_ON_ONCE(bus->state != MDIOBUS_REGISTERED))
+		return;
 	bus->state = MDIOBUS_UNREGISTERED;
 
 	for (i = 0; i < PHY_MAX_ADDR; i++) {
Signature · 1 line
2.30.2
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
#2 lore raw

PATCH v2 1/1 net: mdiobus: get rid of a BUG_ON()

We spotted a bug recently during a review where a driver was unregistering a bus that wasn't registered, which would trigger this BUG_ON(). Let's handle that situation more gracefully, and just print a warning and return.

---
v2: Update the Reported-by tag.

 drivers/net/phy/mdio_bus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/phy/mdio_bus.c +2 -1
index dadf75ff3ab9..6045ad3def12 100644
@@ -607,7 +607,8 @@ void mdiobus_unregister(struct mii_bus *bus)
 	struct mdio_device *mdiodev;
 	int i;
 
-	BUG_ON(bus->state != MDIOBUS_REGISTERED);
+	if (WARN_ON_ONCE(bus->state != MDIOBUS_REGISTERED))
+		return;
 	bus->state = MDIOBUS_UNREGISTERED;
 
 	for (i = 0; i < PHY_MAX_ADDR; i++) {
Signature · 1 line
2.30.2
#3 lore raw
This patch was applied to netdev/net.git (refs/heads/master):

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

Quoted 11 lines · On Mon, 17 May 2021 12:04:13 +0300 you wrote:

We spotted a bug recently during a review where a driver was unregistering a bus that wasn't registered, which would trigger this BUG_ON(). Let's handle that situation more gracefully, and just print a warning and return.

[...]

Here is the summary with links:
- [net,v2] net: mdiobus: get rid of a BUG_ON()

    https://git.kernel.org/netdev/net/c/1dde47a66d4f

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

maintainer Reviewed-by on v1 1/1
#4 lore raw
In reply to Dan Carpenter
Quoted 7 lines · Dan Carpenter

We spotted a bug recently during a review where a driver was unregistering a bus that wasn't registered, which would trigger this BUG_ON(). Let's handle that situation more gracefully, and just print a warning and return.

Andrew