[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200827070618.26754-1-s.hauer@pengutronix.de>
Date: Thu, 27 Aug 2020 09:06:18 +0200
From: Sascha Hauer <s.hauer@...gutronix.de>
To: netdev@...r.kernel.org
Cc: Andrew Lunn <andrew@...n.ch>,
Florian Fainelli <f.fainelli@...il.com>,
Heiner Kallweit <hkallweit1@...il.com>, kernel@...gutronix.de,
Sascha Hauer <s.hauer@...gutronix.de>
Subject: [PATCHi v2] net: mdiobus: fix device unregistering in mdiobus_register
After device_register has been called the device structure may not be
freed anymore, put_device() has to be called instead. This gets violated
when device_register() or any of the following steps before the mdio
bus is fully registered fails. In this case the caller will call
mdiobus_free() which then directly frees the mdio bus structure.
Set bus->state to MDIOBUS_UNREGISTERED right before calling
device_register(). With this mdiobus_free() calls put_device() instead
as it ought to be.
Signed-off-by: Sascha Hauer <s.hauer@...gutronix.de>
---
Changes since v1:
- set bus->state before calling device_register(), not afterwards
drivers/net/phy/mdio_bus.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 0af20faad69d..9434b04a11c8 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -534,6 +534,8 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
bus->dev.groups = NULL;
dev_set_name(&bus->dev, "%s", bus->id);
+ bus->state = MDIOBUS_UNREGISTERED;
+
err = device_register(&bus->dev);
if (err) {
pr_err("mii_bus %s failed to register\n", bus->id);
--
2.28.0
Powered by blists - more mailing lists