Skip to content

Commit

Permalink
net: phylink: move phy_device_free() to correctly release phy device
Browse files Browse the repository at this point in the history
[ Upstream commit ce93fdb ]

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 <clement.leger@bootlin.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
clementleger authored and gregkh committed Feb 14, 2023
1 parent a7f0ec2 commit a65723e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/net/phy/phylink.c
Expand Up @@ -1793,10 +1793,9 @@ int phylink_fwnode_phy_connect(struct phylink *pl,

ret = phy_attach_direct(pl->netdev, phy_dev, flags,
pl->link_interface);
if (ret) {
phy_device_free(phy_dev);
phy_device_free(phy_dev);
if (ret)
return ret;
}

ret = phylink_bringup_phy(pl, phy_dev, pl->link_config.interface);
if (ret)
Expand Down

0 comments on commit a65723e

Please sign in to comment.