In the Linux kernel, the following vulnerability has been resolved:
phy: mdio: fix memory leak
Syzbot reported memory leak in MDIO bus interface, the problem was in wrong state logic.
MDIOBUSALLOCATED indicates 2 states: 1. Bus is only allocated 2. Bus allocated and _mdiobusregister() fails, but deviceregister() was called
In case of deviceregister() has been called we should call putdevice() to correctly free the memory allocated for this device, but mdiobusfree() calls just kfree(dev) in case of MDIOBUSALLOCATED state
To avoid this behaviour we need to set bus->state to MDIOBUSUNREGISTERED _before calling deviceregister(), because putdevice() should be called even in case of device_register() failure.