LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: phylink: move phy_device_free() to correctly release phy device
@ 2023-01-31 10:02 Clément Léger
  2023-02-03 10:00 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Clément Léger @ 2023-01-31 10:02 UTC (permalink / raw
  To: Russell King, Andrew Lunn, Heiner Kallweit, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Grant Likely,
	Calvin Johnson, Ioana Ciornei
  Cc: Clément Léger, netdev, linux-kernel

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: 25396f680dd6 ("net: phylink: introduce phylink_fwnode_phy_connect()")
Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
 drivers/net/phy/phylink.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 09cc65c0da93..4d2519cdb801 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -1812,10 +1812,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)
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] net: phylink: move phy_device_free() to correctly release phy device
  2023-01-31 10:02 [PATCH net] net: phylink: move phy_device_free() to correctly release phy device Clément Léger
@ 2023-02-03 10:00 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-02-03 10:00 UTC (permalink / raw
  To: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2VyIDxjbGVtZW50LmxlZ2VyQGJvb3RsaW4uY29tPg==?=
  Cc: linux, andrew, hkallweit1, davem, edumazet, kuba, pabeni,
	grant.likely, calvin.johnson, ioana.ciornei, netdev, linux-kernel

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Tue, 31 Jan 2023 11:02:42 +0100 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [net] net: phylink: move phy_device_free() to correctly release phy device
    https://git.kernel.org/netdev/net/c/ce93fdb5f2ca

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-03 10:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-31 10:02 [PATCH net] net: phylink: move phy_device_free() to correctly release phy device Clément Léger
2023-02-03 10:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).