1
1

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 <markus.stockhausen@gmx.de>
This commit is contained in:
Markus Stockhausen 2026-05-24 09:34:29 +02:00
parent 246b216df5
commit c5bab7288c

View File

@ -1610,8 +1610,10 @@ static int rteth_probe(struct platform_device *pdev)
phy_mode = PHY_INTERFACE_MODE_NA; phy_mode = PHY_INTERFACE_MODE_NA;
err = of_get_phy_mode(dn, &phy_mode); err = of_get_phy_mode(dn, &phy_mode);
if (err < 0) if (err < 0) {
return dev_err_probe(&pdev->dev, err, "incorrect phy-mode\n"); err = dev_err_probe(&pdev->dev, err, "incorrect phy-mode\n");
goto cleanup;
}
ctrl->phylink_config.dev = &dev->dev; ctrl->phylink_config.dev = &dev->dev;
ctrl->phylink_config.type = PHYLINK_NETDEV; 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, ctrl->phylink = phylink_create(&ctrl->phylink_config, pdev->dev.fwnode,
phy_mode, &rteth_mac_ops); phy_mode, &rteth_mac_ops);
if (IS_ERR(ctrl->phylink)) if (IS_ERR(ctrl->phylink)) {
return dev_err_probe(&pdev->dev, PTR_ERR(ctrl->phylink), err = dev_err_probe(&pdev->dev, PTR_ERR(ctrl->phylink),
"could not create phylink\n"); "could not create phylink\n");
ctrl->phylink = NULL;
goto cleanup;
}
err = devm_register_netdev(&pdev->dev, dev); err = devm_register_netdev(&pdev->dev, dev);
if (err) if (err)
goto cleanup;
return 0;
cleanup:
if (ctrl->phylink)
phylink_destroy(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; return err;
} }