]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: phy: sfp: free mii_bus in sfp_i2c_mdiobus_destroy
authorPetr Wozniak <petr.wozniak@gmail.com>
Sat, 27 Jun 2026 17:32:41 +0000 (19:32 +0200)
committerJakub Kicinski <kuba@kernel.org>
Tue, 30 Jun 2026 02:07:42 +0000 (19:07 -0700)
sfp_i2c_mdiobus_create() allocates the I2C MDIO bus with mdio_i2c_alloc(),
a plain (non-devm) allocation, and registers it. sfp_i2c_mdiobus_destroy()
only unregisters the bus and clears sfp->i2c_mii without calling
mdiobus_free(). As the only reference to the bus is then cleared, the
struct mii_bus is leaked.

This is hit whenever a copper/RollBall SFP module that instantiated an MDIO
bus is removed: sfp_sm_main() takes the global teardown path and calls
sfp_i2c_mdiobus_destroy(). sfp_cleanup(), on driver unbind, frees
sfp->i2c_mii directly, which is why the leak only triggered on module
hot-removal and not on unbind.

Free the bus in sfp_i2c_mdiobus_destroy() to match the allocation done in
sfp_i2c_mdiobus_create().

Fixes: e85b1347ace6 ("net: sfp: create/destroy I2C mdiobus before PHY probe/after PHY release")
Signed-off-by: Petr Wozniak <petr.wozniak@gmail.com>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Reviewed-by: Larysa Zaremba <larysa.zaremba@intel.com>
Link: https://patch.msgid.link/312bde8176fc429aa89524e3be250137f034ba84.1782581445.git.petr.wozniak@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/phy/sfp.c

index 03bfd8640db9635cabfbad21917d4998c0c4e238..c4d274ab651e34ce9fbeb117debaf5535e738343 100644 (file)
@@ -963,6 +963,7 @@ static int sfp_i2c_mdiobus_create(struct sfp *sfp)
 static void sfp_i2c_mdiobus_destroy(struct sfp *sfp)
 {
        mdiobus_unregister(sfp->i2c_mii);
+       mdiobus_free(sfp->i2c_mii);
        sfp->i2c_mii = NULL;
 }