net: usb: lan78xx: Fix memory leak on device unplug by freeing PHY device
authorOleksij Rempel <o.rempel@pengutronix.de>
Sat, 16 Nov 2024 13:05:58 +0000 (14:05 +0100)
committerJakub Kicinski <kuba@kernel.org>
Mon, 25 Nov 2024 00:28:57 +0000 (16:28 -0800)
Add calls to `phy_device_free` after `fixed_phy_unregister` to fix a
memory leak that occurs when the device is unplugged. This ensures
proper cleanup of pseudo fixed-link PHYs.

Fixes: 89b36fb5e532 ("lan78xx: Lan7801 Support for Fixed PHY")
Cc: Raghuram Chary J <raghuramchary.jallipalli@microchip.com>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://patch.msgid.link/20241116130558.1352230-2-o.rempel@pengutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/usb/lan78xx.c

index 094a47b8b97eb2136d673282078ae4baa17a6cdc..9f191b6ce8215244325d9087be7b98dc355a4b12 100644 (file)
@@ -2380,6 +2380,7 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
                if (dev->chipid == ID_REV_CHIP_ID_7801_) {
                        if (phy_is_pseudo_fixed_link(phydev)) {
                                fixed_phy_unregister(phydev);
+                               phy_device_free(phydev);
                        } else {
                                phy_unregister_fixup_for_uid(PHY_KSZ9031RNX,
                                                             0xfffffff0);
@@ -4246,8 +4247,10 @@ static void lan78xx_disconnect(struct usb_interface *intf)
 
        phy_disconnect(net->phydev);
 
-       if (phy_is_pseudo_fixed_link(phydev))
+       if (phy_is_pseudo_fixed_link(phydev)) {
                fixed_phy_unregister(phydev);
+               phy_device_free(phydev);
+       }
 
        usb_scuttle_anchored_urbs(&dev->deferred);