From: Markus Stockhausen Date: Sun, 24 May 2026 07:34:29 +0000 (+0200) Subject: realtek: eth: improve error handling during probe X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c5bab7288c4f8e358d6aad502a4060bd32ca3ca2;p=thirdparty%2Fopenwrt.git realtek: eth: improve error handling during probe The error handling flow during probing has some shortcomings. 1. In case an error occurs after netif_napi_add() this must be cleaned up with a call to netif_napi_del(). 2. If devm_register_netdev() fails not only NAPI must be cleaned up but also the phylink. Add a cleanup section for the probe. Implement it generically (checking for 0/NULL values) so it can be called any time when encountering probe failures. Link: https://github.com/openwrt/openwrt/pull/23483 Signed-off-by: Markus Stockhausen --- diff --git a/target/linux/realtek/files-6.18/drivers/net/ethernet/rtl838x_eth.c b/target/linux/realtek/files-6.18/drivers/net/ethernet/rtl838x_eth.c index 4724bc2bfbe..41b8dcd687f 100644 --- a/target/linux/realtek/files-6.18/drivers/net/ethernet/rtl838x_eth.c +++ b/target/linux/realtek/files-6.18/drivers/net/ethernet/rtl838x_eth.c @@ -1610,8 +1610,10 @@ static int rteth_probe(struct platform_device *pdev) phy_mode = PHY_INTERFACE_MODE_NA; err = of_get_phy_mode(dn, &phy_mode); - if (err < 0) - return dev_err_probe(&pdev->dev, err, "incorrect phy-mode\n"); + if (err < 0) { + err = dev_err_probe(&pdev->dev, err, "incorrect phy-mode\n"); + goto cleanup; + } ctrl->phylink_config.dev = &dev->dev; ctrl->phylink_config.type = PHYLINK_NETDEV; @@ -1622,13 +1624,24 @@ static int rteth_probe(struct platform_device *pdev) ctrl->phylink = phylink_create(&ctrl->phylink_config, pdev->dev.fwnode, phy_mode, &rteth_mac_ops); - if (IS_ERR(ctrl->phylink)) - return dev_err_probe(&pdev->dev, PTR_ERR(ctrl->phylink), + if (IS_ERR(ctrl->phylink)) { + err = dev_err_probe(&pdev->dev, PTR_ERR(ctrl->phylink), "could not create phylink\n"); + ctrl->phylink = NULL; + goto cleanup; + } err = devm_register_netdev(&pdev->dev, dev); if (err) + goto cleanup; + + return 0; + +cleanup: + if (ctrl->phylink) phylink_destroy(ctrl->phylink); + for (int i = 0; i < RTETH_RX_RINGS; i++) + netif_napi_del(&ctrl->rx_qs[i].napi); return err; }