]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
phy: fix error case of phy_led_triggers_(un)register
authorWoojung Huh <woojung.huh@microchip.com>
Wed, 23 Nov 2016 23:10:33 +0000 (23:10 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sat, 26 Nov 2016 00:57:57 +0000 (19:57 -0500)
When phy_init_hw() fails at phy_attach_direct();
- phy_detach() calls phy_led_triggers_unregister() without
  previous call of phy_led_triggers_register().
- still call phy_led_triggers_register() and cause memory leak.

Fixes: 2e0bc452f472 ("net: phy: leds: add support for led triggers on phy link state change")
Signed-off-by: Woojung Huh <woojung.huh@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/phy_device.c
drivers/net/phy/phy_led_triggers.c

index 9e8f048891bd192f748312854a372ac368cacf85..ba86c191a13ea81ca3d38fb8951574d3d4d6c52a 100644 (file)
@@ -914,15 +914,15 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
         */
        err = phy_init_hw(phydev);
        if (err)
-               phy_detach(phydev);
-       else
-               phy_resume(phydev);
+               goto error;
 
+       phy_resume(phydev);
        phy_led_triggers_register(phydev);
 
        return err;
 
 error:
+       phy_detach(phydev);
        put_device(d);
        module_put(bus->owner);
        return err;
index cda600a1b7660ea0872a4c96105eb24100b75d90..fa62bdf2f52694dece215d2b62e548026e482c38 100644 (file)
@@ -130,7 +130,5 @@ void phy_led_triggers_unregister(struct phy_device *phy)
 
        for (i = 0; i < phy->phy_num_led_triggers; i++)
                phy_led_trigger_unregister(&phy->phy_led_triggers[i]);
-
-       devm_kfree(&phy->mdio.dev, phy->phy_led_triggers);
 }
 EXPORT_SYMBOL_GPL(phy_led_triggers_unregister);