Skip to content

Commit cfaa202

Browse files
oleremkuba-moo
authored andcommitted
net: mdiobus: fwnode_mdiobus_register_phy() rework error handling
Rework error handling as preparation for PSE patch. This patch should make it easier to extend this function. Signed-off-by: Oleksij Rempel <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3114b07 commit cfaa202

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

drivers/net/mdio/fwnode_mdio.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
110110
else
111111
phy = phy_device_create(bus, addr, phy_id, 0, NULL);
112112
if (IS_ERR(phy)) {
113-
unregister_mii_timestamper(mii_ts);
114-
return PTR_ERR(phy);
113+
rc = PTR_ERR(phy);
114+
goto clean_mii_ts;
115115
}
116116

117117
if (is_acpi_node(child)) {
@@ -125,17 +125,13 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
125125
/* All data is now stored in the phy struct, so register it */
126126
rc = phy_device_register(phy);
127127
if (rc) {
128-
phy_device_free(phy);
129128
fwnode_handle_put(phy->mdio.dev.fwnode);
130-
return rc;
129+
goto clean_phy;
131130
}
132131
} else if (is_of_node(child)) {
133132
rc = fwnode_mdiobus_phy_device_register(bus, phy, child, addr);
134-
if (rc) {
135-
unregister_mii_timestamper(mii_ts);
136-
phy_device_free(phy);
137-
return rc;
138-
}
133+
if (rc)
134+
goto clean_phy;
139135
}
140136

141137
/* phy->mii_ts may already be defined by the PHY driver. A
@@ -145,5 +141,12 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
145141
if (mii_ts)
146142
phy->mii_ts = mii_ts;
147143
return 0;
144+
145+
clean_phy:
146+
phy_device_free(phy);
147+
clean_mii_ts:
148+
unregister_mii_timestamper(mii_ts);
149+
150+
return rc;
148151
}
149152
EXPORT_SYMBOL(fwnode_mdiobus_register_phy);

0 commit comments

Comments
 (0)