[net] net: mdiobus: get rid of a BUG_ON()
diff mbox series

Message ID YJ+b52c5bGLdewFz@mwanda
State Accepted
Commit 1dde47a66d4fb181830d6fa000e5ea86907b639e
Headers show
Series
  • [net] net: mdiobus: get rid of a BUG_ON()
Related show

Commit Message

Dan Carpenter May 15, 2021, 10:01 a.m. UTC
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 <linux@armlinux.org.uk>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/net/phy/mdio_bus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Russell King (Oracle) May 15, 2021, 10:15 a.m. UTC | #1
On Sat, May 15, 2021 at 01:01:11PM +0300, Dan Carpenter 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.
> 
> Reported-by: Russell King <linux@armlinux.org.uk>

This probably ought to be updated to:

Reported-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

now please.

> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

> ---
>  drivers/net/phy/mdio_bus.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index dadf75ff3ab9..6045ad3def12 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -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++) {
> -- 
> 2.30.2
> 
>
Andrew Lunn May 15, 2021, 2:06 p.m. UTC | #2
On Sat, May 15, 2021 at 01:01:11PM +0300, Dan Carpenter 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.
> 
> Reported-by: Russell King <linux@armlinux.org.uk>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

Patch
diff mbox series

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index dadf75ff3ab9..6045ad3def12 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -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++) {