Messages in this thread | | | Date | Wed, 29 Sep 2021 09:22:26 +0300 | From | Dan Carpenter <> | Subject | Re: [PATCH v2 2/2] phy: mdio: fix memory leak |
| |
On Tue, Sep 28, 2021 at 11:40:15PM +0300, Pavel Skripkin wrote: > Syzbot reported memory leak in MDIO bus interface, the problem was in > wrong state logic. > > MDIOBUS_ALLOCATED indicates 2 states: > 1. Bus is only allocated > 2. Bus allocated and __mdiobus_register() fails, but > device_register() was called > > In case of device_register() has been called we should call put_device() > to correctly free the memory allocated for this device, but mdiobus_free() > calls just kfree(dev) in case of MDIOBUS_ALLOCATED state > > To avoid this behaviour we need to set bus->state to MDIOBUS_UNREGISTERED > _before_ calling device_register(), because put_device() should be > called even in case of device_register() failure. > > Link: https://lore.kernel.org/netdev/YVMRWNDZDUOvQjHL@shell.armlinux.org.uk/ > Fixes: 46abc02175b3 ("phylib: give mdio buses a device tree presence") > Reported-and-tested-by: syzbot+398e7dc692ddbbb4cfec@syzkaller.appspotmail.com > Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
Thanks!
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
regards, dan carpenter
| |