Skip to content

Commit ce93fdb

Browse files
clementlegerdavem330
authored andcommitted
net: phylink: move phy_device_free() to correctly release phy device
After calling fwnode_phy_find_device(), the phy device refcount is incremented. Then, when the phy device is attached to a netdev with phy_attach_direct(), the refcount is also incremented but only decremented in the caller if phy_attach_direct() fails. Move phy_device_free() before the "if" to always release it correctly. Indeed, either phy_attach_direct() failed and we don't want to keep a reference to the phydev or it succeeded and a reference has been taken internally. Fixes: 25396f6 ("net: phylink: introduce phylink_fwnode_phy_connect()") Signed-off-by: Clément Léger <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent edb9b8f commit ce93fdb

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/net/phy/phylink.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,10 +1812,9 @@ int phylink_fwnode_phy_connect(struct phylink *pl,
18121812

18131813
ret = phy_attach_direct(pl->netdev, phy_dev, flags,
18141814
pl->link_interface);
1815-
if (ret) {
1816-
phy_device_free(phy_dev);
1815+
phy_device_free(phy_dev);
1816+
if (ret)
18171817
return ret;
1818-
}
18191818

18201819
ret = phylink_bringup_phy(pl, phy_dev, pl->link_config.interface);
18211820
if (ret)

0 commit comments

Comments
 (0)