]> git.baikalelectronics.ru Git - kernel.git/commit
net: phylink: move phy_device_free() to correctly release phy device
authorClément Léger <clement.leger@bootlin.com>
Tue, 31 Jan 2023 10:02:42 +0000 (11:02 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Feb 2023 18:11:43 +0000 (19:11 +0100)
commitd75a9bc02ce7de7ff6fb6e20a5b452cba1680293
tree910ce1a82bd062e764ed0b1bd2e482eb096a61c7
parentd1e34e063461b0dd839211bec752cfbe770221ca
net: phylink: move phy_device_free() to correctly release phy device

[ Upstream commit 527db15d908b436194ee4d458c0752693f4fceea ]

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: cb6a6b8b808a ("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>
drivers/net/phy/phylink.c