]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
net: phy: fix memory leak in device-create error path
authorJohan Hovold <johan@kernel.org>
Thu, 6 Aug 2020 15:37:53 +0000 (17:37 +0200)
committerThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Fri, 4 Sep 2020 19:29:26 +0000 (16:29 -0300)
BugLink: https://bugs.launchpad.net/bugs/1892417
[ Upstream commit d02cbc46136105cf86f84ac355e16f04696f538d ]

A recent commit introduced a late error path in phy_device_create()
which fails to release the device name allocated by dev_set_name().

Fixes: 13d0ab6750b2 ("net: phy: check return code when requesting PHY driver module")
Cc: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
drivers/net/phy/phy_device.c

index dba52a5c378adb07be4a2de41419159e577ceaa2..110924d627449cbc36adbab7d218a1e695f735f9 100644 (file)
@@ -615,7 +615,9 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
        if (c45_ids)
                dev->c45_ids = *c45_ids;
        dev->irq = bus->irq[addr];
+
        dev_set_name(&mdiodev->dev, PHY_ID_FMT, bus->id, addr);
+       device_initialize(&mdiodev->dev);
 
        dev->state = PHY_DOWN;
 
@@ -649,10 +651,8 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
                ret = phy_request_driver_module(dev, phy_id);
        }
 
-       if (!ret) {
-               device_initialize(&mdiodev->dev);
-       } else {
-               kfree(dev);
+       if (ret) {
+               put_device(&mdiodev->dev);
                dev = ERR_PTR(ret);
        }