diff options
author | Krzysztof Halasa <khc@pm.waw.pl> | 2008-12-25 19:50:41 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-12-25 19:50:41 -0500 |
commit | 161c8d2f50109b44b664eaf23831ea1587979a61 (patch) | |
tree | 1d9b2b4aaa72296f98c449e6f955ade61e84ed02 /drivers | |
parent | f7d1b9f5aafa371d7f51f644aa3c38bc914e9205 (diff) |
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: Krzysztof Halasa <khc@pm.waw.pl>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/phy/mdio_bus.c | 22 | ||||
-rw-r--r-- | drivers/net/phy/phy_device.c | 2 |
2 files changed, 16 insertions, 8 deletions
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 7a333601fbe8..11adf6ed4628 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c | |||
@@ -63,7 +63,9 @@ EXPORT_SYMBOL(mdiobus_alloc); | |||
63 | static void mdiobus_release(struct device *d) | 63 | static void mdiobus_release(struct device *d) |
64 | { | 64 | { |
65 | struct mii_bus *bus = to_mii_bus(d); | 65 | struct mii_bus *bus = to_mii_bus(d); |
66 | BUG_ON(bus->state != MDIOBUS_RELEASED); | 66 | BUG_ON(bus->state != MDIOBUS_RELEASED && |
67 | /* for compatibility with error handling in drivers */ | ||
68 | bus->state != MDIOBUS_ALLOCATED); | ||
67 | kfree(bus); | 69 | kfree(bus); |
68 | } | 70 | } |
69 | 71 | ||
@@ -83,8 +85,7 @@ static struct class mdio_bus_class = { | |||
83 | */ | 85 | */ |
84 | int mdiobus_register(struct mii_bus *bus) | 86 | int mdiobus_register(struct mii_bus *bus) |
85 | { | 87 | { |
86 | int i; | 88 | int i, err; |
87 | int err = 0; | ||
88 | 89 | ||
89 | if (NULL == bus || NULL == bus->name || | 90 | if (NULL == bus || NULL == bus->name || |
90 | NULL == bus->read || | 91 | NULL == bus->read || |
@@ -116,16 +117,23 @@ int mdiobus_register(struct mii_bus *bus) | |||
116 | struct phy_device *phydev; | 117 | struct phy_device *phydev; |
117 | 118 | ||
118 | phydev = mdiobus_scan(bus, i); | 119 | phydev = mdiobus_scan(bus, i); |
119 | if (IS_ERR(phydev)) | 120 | if (IS_ERR(phydev)) { |
120 | err = PTR_ERR(phydev); | 121 | err = PTR_ERR(phydev); |
122 | goto error; | ||
123 | } | ||
121 | } | 124 | } |
122 | } | 125 | } |
123 | 126 | ||
124 | if (!err) | 127 | bus->state = MDIOBUS_REGISTERED; |
125 | bus->state = MDIOBUS_REGISTERED; | ||
126 | |||
127 | pr_info("%s: probed\n", bus->name); | 128 | pr_info("%s: probed\n", bus->name); |
129 | return 0; | ||
128 | 130 | ||
131 | error: | ||
132 | while (--i >= 0) { | ||
133 | if (bus->phy_map[i]) | ||
134 | device_unregister(&bus->phy_map[i]->dev); | ||
135 | } | ||
136 | device_del(&bus->dev); | ||
129 | return err; | 137 | return err; |
130 | } | 138 | } |
131 | EXPORT_SYMBOL(mdiobus_register); | 139 | EXPORT_SYMBOL(mdiobus_register); |
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index f84f6a1b530c..e35460165bf7 100644 --- 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) | |||
232 | return NULL; | 232 | return NULL; |
233 | 233 | ||
234 | /* | 234 | /* |
235 | * Broken hardware is sometimes missing the pull down resistor on the | 235 | * Broken hardware is sometimes missing the pull-up resistor on the |
236 | * MDIO line, which results in reads to non-existent devices returning | 236 | * MDIO line, which results in reads to non-existent devices returning |
237 | * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent | 237 | * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent |
238 | * device as well. | 238 | * device as well. |