Netdev List
 help / color / mirror / Atom feed
From: Linkui Xiao <xiaolinkui@126.com>
To: andrew@lunn.ch
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, rosenp@gmail.com,
	jacob.e.keller@intel.com, daniel.machon@microchip.com,
	chunkeey@gmail.com, kees+treewide@kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	xiaolinkui@kylinos.cn
Subject: [PATCH net v2 1/2] net: ibm: emac: attach the fixed-link PHY with of_phy_connect()
Date: Mon, 23 Nov 2026 17:32:00 +0800	[thread overview]
Message-ID: <20261123093201.770552-2-xiaolinkui@126.com> (raw)
In-Reply-To: <20261123093201.770552-1-xiaolinkui@126.com>

From: Linkui Xiao <xiaolinkui@kylinos.cn>

emac_init_phy() sets ndev->phydev by hand for a fixed link, so
phy_attach_direct() never runs: the PHY stays out of the netdev's PHY
link topology, and ETHTOOL_MSG_PHY_GET then dereferences a NULL
link_topo in phy_prepare_data().

Use of_phy_connect(), as gianfar, fec, davinci_emac and nixge do, and as
this driver already does for the phy-handle case.  It attaches the PHY
and drops the of_phy_find_device() reference, so put_device() goes away.
It only installs emac_adjust_link() as phydev->adjust_link though, and
the state machine is not started for a fixed link, so the explicit call
that copies the link parameters into dev->phy stays.

Attaching also means detaching.  Without phy_disconnect(), unbind leaves
phydev->attached_dev pointing at a freed netdev and the next probe fails
with -EBUSY from phy_attach_direct().  This fixes the phy-handle path as
well, which calls phy_start() but never phy_stop().

Fixes: baab9de385a8 ("net: ibm: emac: use netdev's phydev directly")
Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn>
---
 drivers/net/ethernet/ibm/emac/core.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/ibm/emac/core.c b/drivers/net/ethernet/ibm/emac/core.c
index 1b95b4d5deff..ba02cf878a12 100644
--- a/drivers/net/ethernet/ibm/emac/core.c
+++ b/drivers/net/ethernet/ibm/emac/core.c
@@ -2673,11 +2673,16 @@ static int emac_init_phy(struct emac_instance *dev)
 				return res;
 
 			res = of_phy_register_fixed_link(np);
-			ndev->phydev = of_phy_find_device(np);
-			if (res || !ndev->phydev)
-				return res ? res : -EINVAL;
-			emac_adjust_link(dev->ndev);
-			put_device(&ndev->phydev->mdio.dev);
+			if (res)
+				return res;
+
+			if (!of_phy_connect(ndev, np, &emac_adjust_link, 0,
+					    dev->phy_mode)) {
+				of_phy_deregister_fixed_link(np);
+				return -EINVAL;
+			}
+
+			emac_adjust_link(ndev);
 		}
 		return 0;
 	}
@@ -3190,6 +3195,10 @@ static int emac_probe(struct platform_device *ofdev)
 	/* I have a bad feeling about this ... */
 
  err_detach_tah:
+	if (ndev->phydev)
+		phy_disconnect(ndev->phydev);
+	if (of_phy_is_fixed_link(np))
+		of_phy_deregister_fixed_link(np);
 	if (emac_has_feature(dev, EMAC_FTR_HAS_TAH))
 		tah_detach(dev->tah_dev, dev->tah_port);
  err_detach_rgmii:
@@ -3223,6 +3232,11 @@ static void emac_remove(struct platform_device *ofdev)
 
 	cancel_work_sync(&dev->reset_work);
 
+	if (dev->ndev->phydev)
+		phy_disconnect(dev->ndev->phydev);
+	if (of_phy_is_fixed_link(ofdev->dev.of_node))
+		of_phy_deregister_fixed_link(ofdev->dev.of_node);
+
 	if (emac_has_feature(dev, EMAC_FTR_HAS_TAH))
 		tah_detach(dev->tah_dev, dev->tah_port);
 	if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII))
-- 
2.25.1


  reply	other threads:[~2026-11-23  9:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  9:31 [PATCH net v2 0/2] net: ibm: emac: fix the fixed-link PHY setup Linkui Xiao
2026-11-23  9:32 ` Linkui Xiao [this message]
2026-11-23  9:32 ` [PATCH net v2 2/2] net: ibm: emac: read the fixed-link status before adjusting the link Linkui Xiao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261123093201.770552-2-xiaolinkui@126.com \
    --to=xiaolinkui@126.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew@lunn.ch \
    --cc=chunkeey@gmail.com \
    --cc=daniel.machon@microchip.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=jacob.e.keller@intel.com \
    --cc=kees+treewide@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rosenp@gmail.com \
    --cc=xiaolinkui@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox