[PATCH] net: airoha_eth: fix mt7531 mdio related initialization bug

Mikhail Kshevetskiy mikhail.kshevetskiy at iopsys.eu
Sun May 31 12:08:08 CEST 2026


Private data isn't ready during bind time. The call of dev_get_priv()
function will return NULL. Thus we can't save mdio device pointer and
use it later during probe.

To solve an issue, we will move the mdio initialization to the probe
function.

Fixes: 96d9e7c46425 ("net: airoha: use mt7531 mdio for GDM1")
Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy at iopsys.eu>
---
 drivers/net/airoha_eth.c | 43 ++++++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 15 deletions(-)

diff --git a/drivers/net/airoha_eth.c b/drivers/net/airoha_eth.c
index 84ee9b2ad76..9fc09824d5b 100644
--- a/drivers/net/airoha_eth.c
+++ b/drivers/net/airoha_eth.c
@@ -365,6 +365,8 @@ static const char * const en7581_xsi_rsts_names[] = {
 	"xfp-mac",
 };
 
+static int airoha_switch_mdio_init(struct udevice *dev);
+
 static u32 airoha_rr(void __iomem *base, u32 offset)
 {
 	return readl(base + offset);
@@ -908,10 +910,7 @@ static int airoha_eth_probe(struct udevice *dev)
 	if (ret)
 		return ret;
 
-	if (eth->switch_mdio_dev) {
-		if (!device_probe(eth->switch_mdio_dev))
-			debug("Warning: failed to probe airoha switch mdio\n");
-	}
+	airoha_switch_mdio_init(dev);
 
 	ofnode_for_each_subnode(node, dev_ofnode(dev)) {
 		if (!ofnode_device_is_compatible(node, "airoha,eth-mac"))
@@ -1202,37 +1201,51 @@ static int arht_eth_write_hwaddr(struct udevice *dev)
 
 static int airoha_eth_bind(struct udevice *dev)
 {
-	struct airoha_eth_soc_data *data = (void *)dev_get_driver_data(dev);
-	struct airoha_eth *eth = dev_get_priv(dev);
-	ofnode switch_node, mdio_node;
-	int ret;
-
 	/*
 	 * Force Probe as we set the Main ETH driver as misc
 	 * to register multiple eth port for each GDM
 	 */
 	dev_or_flags(dev, DM_FLAG_PROBE_AFTER_BIND);
 
+	return 0;
+}
+
+static int airoha_switch_mdio_init(struct udevice *dev)
+{
+	struct airoha_eth_soc_data *data = (void *)dev_get_driver_data(dev);
+	struct airoha_eth *eth = dev_get_priv(dev);
+	ofnode switch_node, mdio_node;
+	int ret;
+
 	if (!CONFIG_IS_ENABLED(MDIO_MT7531_MMIO))
 		return 0;
 
 	switch_node = ofnode_by_compatible(ofnode_null(),
 					   data->switch_compatible);
 	if (!ofnode_valid(switch_node)) {
-		debug("Warning: missing switch node\n");
-		return 0;
+		debug("Warning: missing airoha switch node\n");
+		return -EINVAL;
 	}
 
 	mdio_node = ofnode_find_subnode(switch_node, "mdio");
 	if (!ofnode_valid(mdio_node)) {
-		debug("Warning: missing mdio node\n");
-		return 0;
+		debug("Warning: missing airoha switch mdio subnode\n");
+		return -EINVAL;
 	}
 
 	ret = device_bind_driver_to_node(dev, "mt7531-mdio-mmio", "mt7531-mdio",
 					 mdio_node, &eth->switch_mdio_dev);
-	if (ret)
-		debug("Warning: failed to bind mdio controller\n");
+	if (ret) {
+		debug("Warning: failed to bind airoha switch mdio\n");
+		return ret;
+	}
+
+	ret = device_probe(eth->switch_mdio_dev);
+	if (ret) {
+		eth->switch_mdio_dev = NULL;
+		debug("Warning: failed to probe airoha switch mdio\n");
+		return ret;
+	}
 
 	return 0;
 }
-- 
2.53.0



More information about the U-Boot mailing list