Skip to content

Commit efeb214

Browse files
lunnPaolo Abeni
authored andcommitted
net: ftgmac100: Always register the MDIO bus when it exists
Both the Aspeed 2400 and 2500 and the original faraday version of the MAC have MDIO bus controllers as part of the MAC. Since it exists, always registering it makes the code simpler, and causes no harm. If there is no mdio node in device tree, of_mdiobus_register() will fall back to mdiobus_register(), making it safe. AST2600 uses an external MDIO controller and does not have an embedded MDIO bus in the MAC. For such configurations, the legacy MII probe path must not be entered without a registered mii_bus. Add an explicit check to fail gracefully when no MDIO bus is present, preventing a NULL pointer dereference while keeping the intended behavior for platforms without embedded MDIO. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: Jacky Chou <jacky_chou@aspeedtech.com> Link: https://patch.msgid.link/20260206-ftgmac-cleanup-v5-9-ad28a9067ea7@aspeedtech.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 7535d70 commit efeb214

1 file changed

Lines changed: 20 additions & 25 deletions

File tree

drivers/net/ethernet/faraday/ftgmac100.c

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,11 @@ static int ftgmac100_mii_probe(struct net_device *netdev)
14831483
phy_interface_t phy_intf;
14841484
int err;
14851485

1486+
if (!priv->mii_bus) {
1487+
dev_err(priv->dev, "No MDIO bus available\n");
1488+
return -ENODEV;
1489+
}
1490+
14861491
/* Default to RGMII. It's a gigabit part after all */
14871492
err = of_get_phy_mode(np, &phy_intf);
14881493
if (err)
@@ -1968,32 +1973,28 @@ static int ftgmac100_probe(struct platform_device *pdev)
19681973
priv->txdes0_edotr_mask = BIT(15);
19691974
}
19701975

1976+
if (priv->mac_id == FTGMAC100_FARADAY ||
1977+
priv->mac_id == FTGMAC100_AST2400 ||
1978+
priv->mac_id == FTGMAC100_AST2500) {
1979+
err = ftgmac100_setup_mdio(netdev);
1980+
if (err)
1981+
return err;
1982+
}
1983+
19711984
if (np && of_get_property(np, "use-ncsi", NULL)) {
19721985
err = ftgmac100_probe_ncsi(netdev, priv, pdev);
19731986
if (err)
1974-
goto err_setup_mdio;
1987+
goto err;
19751988
} else if (np && (of_phy_is_fixed_link(np) ||
19761989
of_get_property(np, "phy-handle", NULL))) {
19771990
struct phy_device *phy;
19781991

1979-
/* Support "mdio"/"phy" child nodes for ast2400/2500 with
1980-
* an embedded MDIO controller. Automatically scan the DTS for
1981-
* available PHYs and register them.
1982-
*/
1983-
if (of_get_property(np, "phy-handle", NULL) &&
1984-
(priv->mac_id == FTGMAC100_AST2400 ||
1985-
priv->mac_id == FTGMAC100_AST2500)) {
1986-
err = ftgmac100_setup_mdio(netdev);
1987-
if (err)
1988-
goto err_setup_mdio;
1989-
}
1990-
19911992
phy = of_phy_get_and_connect(priv->netdev, np,
19921993
&ftgmac100_adjust_link);
19931994
if (!phy) {
19941995
dev_err(&pdev->dev, "Failed to connect to phy\n");
19951996
err = -EINVAL;
1996-
goto err_phy_connect;
1997+
goto err;
19971998
}
19981999

19992000
/* Indicate that we support PAUSE frames (see comment in
@@ -2010,28 +2011,25 @@ static int ftgmac100_probe(struct platform_device *pdev)
20102011
* PHYs.
20112012
*/
20122013
priv->use_ncsi = false;
2013-
err = ftgmac100_setup_mdio(netdev);
2014-
if (err)
2015-
goto err_setup_mdio;
20162014

20172015
err = ftgmac100_mii_probe(netdev);
20182016
if (err) {
20192017
dev_err(priv->dev, "MII probe failed!\n");
2020-
goto err_ncsi_dev;
2018+
goto err;
20212019
}
20222020

20232021
}
20242022

20252023
priv->rst = devm_reset_control_get_optional_exclusive(priv->dev, NULL);
20262024
if (IS_ERR(priv->rst)) {
20272025
err = PTR_ERR(priv->rst);
2028-
goto err_phy_connect;
2026+
goto err;
20292027
}
20302028

20312029
if (priv->is_aspeed) {
20322030
err = ftgmac100_setup_clk(priv);
20332031
if (err)
2034-
goto err_phy_connect;
2032+
goto err;
20352033

20362034
/* Disable ast2600 problematic HW arbitration */
20372035
if (priv->mac_id == FTGMAC100_AST2600)
@@ -2067,21 +2065,18 @@ static int ftgmac100_probe(struct platform_device *pdev)
20672065
err = register_netdev(netdev);
20682066
if (err) {
20692067
dev_err(&pdev->dev, "Failed to register netdev\n");
2070-
goto err_register_netdev;
2068+
goto err;
20712069
}
20722070

20732071
netdev_info(netdev, "irq %d, mapped at %p\n", netdev->irq, priv->base);
20742072

20752073
return 0;
20762074

2077-
err_register_netdev:
2078-
err_phy_connect:
2075+
err:
20792076
ftgmac100_phy_disconnect(netdev);
2080-
err_ncsi_dev:
20812077
if (priv->ndev)
20822078
ncsi_unregister_dev(priv->ndev);
20832079
ftgmac100_destroy_mdio(netdev);
2084-
err_setup_mdio:
20852080
return err;
20862081
}
20872082

0 commit comments

Comments
 (0)