* [PATCH] PHYLIB mdio fixes #2
@ 2008-12-19 19:52 Krzysztof Halasa
2008-12-26 0:50 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Krzysztof Halasa @ 2008-12-19 19:52 UTC (permalink / raw)
To: Lennert Buytenhek; +Cc: David Miller, netdev
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: Krzysztof Halasa <khc@pm.waw.pl>
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -63,7 +63,9 @@ EXPORT_SYMBOL(mdiobus_alloc);
static void mdiobus_release(struct device *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);
}
@@ -83,8 +85,7 @@ static struct class mdio_bus_class = {
*/
int mdiobus_register(struct mii_bus *bus)
{
- int i;
- int err = 0;
+ int i, err;
if (NULL == bus || NULL == bus->name ||
NULL == bus->read ||
@@ -116,16 +117,23 @@ int mdiobus_register(struct mii_bus *bus)
struct phy_device *phydev;
phydev = mdiobus_scan(bus, i);
- if (IS_ERR(phydev))
+ if (IS_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);
+ return 0;
+error:
+ while (--i >= 0) {
+ if (bus->phy_map[i])
+ device_unregister(&bus->phy_map[i]->dev);
+ }
+ device_del(&bus->dev);
return err;
}
EXPORT_SYMBOL(mdiobus_register);
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -232,7 +232,7 @@ struct phy_device * get_phy_device(struct mii_bus *bus, int addr)
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
* 0 rather than 0xffff. Catch this here and treat 0 as a non-existent
* device as well.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] PHYLIB mdio fixes #2
2008-12-19 19:52 [PATCH] PHYLIB mdio fixes #2 Krzysztof Halasa
@ 2008-12-26 0:50 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2008-12-26 0:50 UTC (permalink / raw)
To: khc; +Cc: buytenh, netdev
From: Krzysztof Halasa <khc@pm.waw.pl>
Date: Fri, 19 Dec 2008 20:52:36 +0100
> 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: Krzysztof Halasa <khc@pm.waw.pl>
Applied, thank you.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-12-26 0:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-19 19:52 [PATCH] PHYLIB mdio fixes #2 Krzysztof Halasa
2008-12-26 0:50 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).