Commit 161c8d2f authored by Krzysztof Halasa's avatar Krzysztof Halasa Committed by David S. Miller

net: PHYLIB mdio fixes #2

The PHYLIB mdio code has more problems in error paths:
- mdiobus_release can be called before bus->state is set to
  MDIOBUS_REGISTERED
- mdiobus_scan allocates resources which need to be freed
- the comment is wrong, the resistors used are actually pull-ups.
Signed-off-by: default avatarKrzysztof Halasa <khc@pm.waw.pl>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f7d1b9f5
...@@ -63,7 +63,9 @@ EXPORT_SYMBOL(mdiobus_alloc); ...@@ -63,7 +63,9 @@ EXPORT_SYMBOL(mdiobus_alloc);
static void mdiobus_release(struct device *d) static void mdiobus_release(struct device *d)
{ {
struct mii_bus *bus = to_mii_bus(d); struct mii_bus *bus = to_mii_bus(d);
BUG_ON(bus->state != MDIOBUS_RELEASED); BUG_ON(bus->state != MDIOBUS_RELEASED &&
/* for compatibility with error handling in drivers */
bus->state != MDIOBUS_ALLOCATED);
kfree(bus); kfree(bus);
} }
...@@ -83,8 +85,7 @@ static struct class mdio_bus_class = { ...@@ -83,8 +85,7 @@ static struct class mdio_bus_class = {
*/ */
int mdiobus_register(struct mii_bus *bus) int mdiobus_register(struct mii_bus *bus)
{ {
int i; int i, err;
int err = 0;
if (NULL == bus || NULL == bus->name || if (NULL == bus || NULL == bus->name ||
NULL == bus->read || NULL == bus->read ||
...@@ -116,16 +117,23 @@ int mdiobus_register(struct mii_bus *bus) ...@@ -116,16 +117,23 @@ int mdiobus_register(struct mii_bus *bus)
struct phy_device *phydev; struct phy_device *phydev;
phydev = mdiobus_scan(bus, i); phydev = mdiobus_scan(bus, i);
if (IS_ERR(phydev)) if (IS_ERR(phydev)) {
err = PTR_ERR(phydev); err = PTR_ERR(phydev);
goto error;
}
} }
} }
if (!err)
bus->state = MDIOBUS_REGISTERED; bus->state = MDIOBUS_REGISTERED;
pr_info("%s: probed\n", bus->name); pr_info("%s: probed\n", bus->name);
return 0;
error:
while (--i >= 0) {
if (bus->phy_map[i])
device_unregister(&bus->phy_map[i]->dev);
}
device_del(&bus->dev);
return err; return err;
} }
EXPORT_SYMBOL(mdiobus_register); EXPORT_SYMBOL(mdiobus_register);
......
...@@ -232,7 +232,7 @@ struct phy_device * get_phy_device(struct mii_bus *bus, int addr) ...@@ -232,7 +232,7 @@ struct phy_device * get_phy_device(struct mii_bus *bus, int addr)
return NULL; return NULL;
/* /*
* Broken hardware is sometimes missing the pull down resistor on the * Broken hardware is sometimes missing the pull-up resistor on the
* MDIO line, which results in reads to non-existent devices returning * MDIO line, which results in reads to non-existent devices returning
* 0 rather than 0xffff. Catch this here and treat 0 as a non-existent * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent
* device as well. * device as well.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment