mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 18:09:56 +00:00
net: mdiobus: fix double put fwnode in the error path
If phy_device_register() or fwnode_mdiobus_phy_device_register()
fail, phy_device_free() is called, the device refcount is decreased
to 0, then fwnode_handle_put() will be called in phy_device_release(),
but in the error path, fwnode_handle_put() has already been called,
so set fwnode to NULL after fwnode_handle_put() in the error path to
avoid double put.
Fixes: cdde156011 ("net: mdiobus: fix unbalanced node reference count")
Reported-by: Zeng Heng <zengheng4@huawei.com>
Tested-by: Zeng Heng <zengheng4@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Zeng Heng <zengheng4@huawei.com>
Tested-by: Zeng Heng <zengheng4@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
25f427ac7b
commit
165df24186
@@ -98,6 +98,7 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio,
|
|||||||
*/
|
*/
|
||||||
rc = phy_device_register(phy);
|
rc = phy_device_register(phy);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
|
device_set_node(&phy->mdio.dev, NULL);
|
||||||
fwnode_handle_put(child);
|
fwnode_handle_put(child);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -153,7 +154,8 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
|
|||||||
/* All data is now stored in the phy struct, so register it */
|
/* All data is now stored in the phy struct, so register it */
|
||||||
rc = phy_device_register(phy);
|
rc = phy_device_register(phy);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
fwnode_handle_put(phy->mdio.dev.fwnode);
|
phy->mdio.dev.fwnode = NULL;
|
||||||
|
fwnode_handle_put(child);
|
||||||
goto clean_phy;
|
goto clean_phy;
|
||||||
}
|
}
|
||||||
} else if (is_of_node(child)) {
|
} else if (is_of_node(child)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user