net: mdiobus: get rid of a BUG_ON()
authorDan Carpenter <dan.carpenter@oracle.com>
Mon, 17 May 2021 09:04:13 +0000 (12:04 +0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 17 May 2021 22:50:58 +0000 (15:50 -0700)
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.

Reported-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/mdio_bus.c

index dadf75ff3ab938f9dd0ae7a70ec65f62c9ebef85..6045ad3def1235fe60a550967d39a25aa8446cad 100644 (file)
@@ -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++) {