Skip to contentSkip to conversation

net: hisilicon: hns_dsaf_mac: fix mdio device leak in hns_mac_register_phy()

PATCH Applied Wentao Liang 3 participants 3 messages Sep 17 – Sep 22

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: hisilicon: hns_dsaf_mac: fix mdio device leak in hns_mac_register_phy()

hns_dsaf_find_platform_device() returns the mdio platform device with its reference count incremented. hns_mac_register_phy() never drops that reference, so the mdio device can not be released.

Release the reference on both the deferred probe and the normal path.

Fixes 1d1afa2ebf82 ("net: hns: register phy device in each mac initial sequence")
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c +3 -0
index bc6b269be299..f1cb6d56e4b9 100644
@@ -793,6 +793,7 @@ static int hns_mac_register_phy(struct hns_mac_cb *mac_cb)
 		dev_err(mac_cb->dev,
 			"mac%d mdio is NULL, dsaf will probe again later\n",
 			mac_cb->mac_id);
+		put_device(&pdev->dev);
 		return -EPROBE_DEFER;
 	}
 
@@ -801,6 +802,8 @@ static int hns_mac_register_phy(struct hns_mac_cb *mac_cb)
 		dev_dbg(mac_cb->dev, "mac%d register phy addr:%d\n",
 			mac_cb->mac_id, addr);
 
+	put_device(&pdev->dev);
+
 	return rc;
 }
 
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Wentao Liang

hns_dsaf_find_platform_device() returns the mdio platform device with its reference count incremented. hns_mac_register_phy() never drops that reference, so the mdio device can not be released.

Release the reference on both the deferred probe and the normal path.

Fixes 1d1afa2ebf82 ("net: hns: register phy device in each mac initial sequence")
#2 lore raw
In reply to Wentao Liang
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 11 lines · On Thu, 17 Sep 2026 11:08:28 +0000 you wrote:

hns_dsaf_find_platform_device() returns the mdio platform device with its reference count incremented. hns_mac_register_phy() never drops that reference, so the mdio device can not be released.

Release the reference on both the deferred probe and the normal path.

Fixes 1d1afa2ebf82 ("net: hns: register phy device in each mac initial sequence")

[...]

Here is the summary with links:
- net: hisilicon: hns_dsaf_mac: fix mdio device leak in hns_mac_register_phy()

    https://git.kernel.org/netdev/net/c/999e8295bc41

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html