Skip to content

Commit d02cbc4

Browse files
jhovolddavem330
authored andcommitted
net: phy: fix memory leak in device-create error path
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: 13d0ab6 ("net: phy: check return code when requesting PHY driver module") Cc: Heiner Kallweit <[email protected]> Signed-off-by: Johan Hovold <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1c3b63f commit d02cbc4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/net/phy/phy_device.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,9 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
615615
if (c45_ids)
616616
dev->c45_ids = *c45_ids;
617617
dev->irq = bus->irq[addr];
618+
618619
dev_set_name(&mdiodev->dev, PHY_ID_FMT, bus->id, addr);
620+
device_initialize(&mdiodev->dev);
619621

620622
dev->state = PHY_DOWN;
621623

@@ -649,10 +651,8 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
649651
ret = phy_request_driver_module(dev, phy_id);
650652
}
651653

652-
if (!ret) {
653-
device_initialize(&mdiodev->dev);
654-
} else {
655-
kfree(dev);
654+
if (ret) {
655+
put_device(&mdiodev->dev);
656656
dev = ERR_PTR(ret);
657657
}
658658

0 commit comments

Comments
 (0)