Skip to content

Commit 165df24

Browse files
Yang Yingliangdavem330
authored andcommitted
net: mdiobus: fix double put fwnode in the error path
If phy_device_register() or fwnode_mdiobus_phy_device_register() fail, phy_device_free() is called, the device refcount is decreased to 0, then fwnode_handle_put() will be called in phy_device_release(), but in the error path, fwnode_handle_put() has already been called, so set fwnode to NULL after fwnode_handle_put() in the error path to avoid double put. Fixes: cdde156 ("net: mdiobus: fix unbalanced node reference count") Reported-by: Zeng Heng <[email protected]> Tested-by: Zeng Heng <[email protected]> Signed-off-by: Yang Yingliang <[email protected]> Reviewed-by: Zeng Heng <[email protected]> Tested-by: Zeng Heng <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 25f427a commit 165df24

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/net/mdio/fwnode_mdio.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio,
9898
*/
9999
rc = phy_device_register(phy);
100100
if (rc) {
101+
device_set_node(&phy->mdio.dev, NULL);
101102
fwnode_handle_put(child);
102103
return rc;
103104
}
@@ -153,7 +154,8 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
153154
/* All data is now stored in the phy struct, so register it */
154155
rc = phy_device_register(phy);
155156
if (rc) {
156-
fwnode_handle_put(phy->mdio.dev.fwnode);
157+
phy->mdio.dev.fwnode = NULL;
158+
fwnode_handle_put(child);
157159
goto clean_phy;
158160
}
159161
} else if (is_of_node(child)) {

0 commit comments

Comments
 (0)