This series fixes resource leaks in the zynq_gem probe error path and remove(), and stops zynq_gem from tearing down an MDIO bus it does not own.
Patch 1 stops zynq_gem from unregistering/freeing an MDIO bus (and the phy_device on it) borrowed from another controller via eth_phy_get_mdio_bus(). Patches 2-4 plug the probe error path and remove() leaks, including the SGMII serdes generic PHY. The eth-phy patch (4/4 up to v3) is now sent separately, so that it can go through the net tree. Tested on QEMU (xilinx-zynq-a9, xilinx_zynq_virt) with a DT in which gem1 shares gem0's MDIO bus and PHY. These runs were done with the eth-phy patch applied, as it was part of the series at the time: - repeated unbind/bind of gem0: heap usage is stable. Without the series the remove() leak eventually exhausts the heap; - unbind of gem1 (shared bus): gem0 keeps working. Without the series, gem0's MDIO bus is freed and its next use data-aborts; - injected failures at each probe step (except the SGMII-only ones) for both gem0 and gem1, followed by a successful re-probe, without leaks. The SGMII generic PHY handling was tested on the same QEMU machine, with gem0 set to phy-mode = "sgmii" and a nop-phy standing in for the serdes (QEMU does not model the PS-GTR): - repeated unbind/bind of gem0: the generic PHY's init and power-on counts return to zero on each remove, and each probe re-initialises and powers it on. Without patch 4 both counts climb by one per cycle, so later probes never reach the PHY's init/power_on ops; - a probe failure after generic_phy_init() (no PHY at the phy-handle address): the generic PHY is exited, and repeated re-probes start from a zero init count. Changes in v4: - Rebased onto current main - Drop the eth-phy patch (v3 4/4); it is now sent separately for the net tree (Michal Simek) - 2/4: keep the SGMII generic PHY in priv->serdes rather than a probe() local, so that remove() can release it; drop the zero-initialisation of struct phy, as priv is zero-allocated (Michal Simek) - 4/4: new patch: power off and exit the serdes PHY in remove() (Michal Simek) - Link to v3: https://lore.kernel.org/r/[email protected] Changes in v3: - Rebased onto current main - Split v2 1/2 into three patches: shared-bus handling (1/4), probe error path (2/4) and .remove buffers (3/4) (Michal Simek) - 1/4: also only free priv->phydev when the bus is our own - 2/4: free priv->phydev on failures after zynq_phy_init(), again only when the MDIO bus is ours - 2/4: call generic_phy_exit() on every error path after generic_phy_init(), including the early returns after zynq_gem_reset_init() and the rxbuffers allocation, and zero-initialise struct phy - 2/4: use descriptive error labels - 4/4: rebased onto the eth-phy reset control support; also release the reset control with reset_free(). Use per-feature DM_GPIO/DM_RESET guards, and reword the subject accordingly Changes in v2: - Move mdio_free() out of the mdio_register_seq() failure branch and into the error label ladder - With CONFIG_DM_ETH_PHY, priv->bus may be a shared bus obtained from eth_phy_get_mdio_bus(). Track whether we allocated it and only unregister/free it in that case, in both probe and remove Signed-off-by: Graeme Smecher <[email protected]> --- Graeme Smecher (4): net: zynq_gem: don't tear down a shared MDIO bus net: zynq_gem: plug resource leaks in .probe error path net: zynq_gem: free buffers in .remove net: zynq_gem: release the SGMII serdes PHY in .remove drivers/net/zynq_gem.c | 70 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 23 deletions(-) --- base-commit: 709a97a05df66e394f40d249105d0baade46f107 change-id: 20261103-zynq-gem-remove-leak-b2b5afccebcb Best regards, -- Graeme Smecher <[email protected]>
