]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: eth: improve error handling during probe
authorMarkus Stockhausen <markus.stockhausen@gmx.de>
Sun, 24 May 2026 07:34:29 +0000 (09:34 +0200)
committerMarkus Stockhausen <markus.stockhausen@gmx.de>
Sat, 30 May 2026 06:50:00 +0000 (08:50 +0200)
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 <markus.stockhausen@gmx.de>
target/linux/realtek/files-6.18/drivers/net/ethernet/rtl838x_eth.c

index 4724bc2bfbe03e84c19da58eda429f7c3fc85860..41b8dcd687f2e57c31dcef1f3470f44de265702d 100644 (file)
@@ -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;
 }