Pavel Skripkin ca6e11c337 phy: mdio: fix memory leak
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
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
Link: https://lore.kernel.org/r/eceae1429fbf8fa5c73dd2a0d39d525aa905074d.1633024062.git.paskripkin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-09-30 17:11:59 -07:00
..
2021-09-01 08:44:42 -07:00
2021-09-11 14:48:42 -07:00
2021-09-01 15:25:28 -07:00
2021-09-07 12:38:59 -07:00
2021-09-09 11:48:27 -07:00
2021-09-09 11:39:57 -07:00
2021-09-08 11:50:26 -07:00
2021-09-09 11:07:47 -07:00
2021-09-30 12:11:35 -07:00
2021-09-24 10:14:19 -07:00
2021-09-15 17:18:56 -07:00
2021-09-02 13:49:39 -07:00
2021-09-11 14:48:42 -07:00
2021-09-01 09:51:16 -07:00
2021-09-03 15:33:47 -07:00
2021-09-27 13:05:12 -07:00
2021-09-01 08:44:42 -07:00
2021-09-07 12:38:59 -07:00
2021-09-30 17:11:59 -07:00
2021-09-09 11:48:27 -07:00
2021-09-21 09:17:15 +02:00
2021-09-25 15:37:31 -07:00
2021-09-20 12:43:34 +01:00
2021-09-20 11:11:54 +01:00
2021-09-01 15:25:28 -07:00
2021-09-28 16:06:31 -07:00
2021-09-01 08:44:42 -07:00
2021-09-01 15:25:28 -07:00
2021-09-01 10:29:29 -07:00
2021-09-22 11:58:24 -07:00
2021-09-27 13:05:12 -07:00
2021-09-14 11:18:47 +02:00
2021-09-24 10:22:53 +02:00
2021-09-28 07:27:29 -07:00
2021-09-18 11:15:01 -07:00
2021-09-25 15:37:31 -07:00