diff options
| author | Yang Yingliang <yangyingliang@huawei.com> | 2022-12-02 13:18:33 +0800 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-12-14 11:41:00 +0100 |
| commit | 6c16f9d425d0d475e12b46b8ff3a002075f00c56 (patch) | |
| tree | e14afdc4b7fb1eaf842437a6046d8fa941a0abf7 | |
| parent | 326edea88c81462eb98efd2f5f8fb63b13e19715 (diff) | |
| download | linux-6c16f9d425d0d475e12b46b8ff3a002075f00c56.tar.gz linux-6c16f9d425d0d475e12b46b8ff3a002075f00c56.tar.bz2 linux-6c16f9d425d0d475e12b46b8ff3a002075f00c56.zip | |
net: mdiobus: fix double put fwnode in the error path
[ Upstream commit 165df24186ecea95705505627df3dacf5e7ff6bf ]
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: cdde1560118f ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
| -rw-r--r-- | drivers/net/mdio/fwnode_mdio.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c index 403b07f8ec2c..2c47efdae73b 100644 --- a/drivers/net/mdio/fwnode_mdio.c +++ b/drivers/net/mdio/fwnode_mdio.c @@ -77,6 +77,7 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio, */ rc = phy_device_register(phy); if (rc) { + device_set_node(&phy->mdio.dev, NULL); fwnode_handle_put(child); return rc; } @@ -125,7 +126,8 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, /* All data is now stored in the phy struct, so register it */ rc = phy_device_register(phy); if (rc) { - fwnode_handle_put(phy->mdio.dev.fwnode); + phy->mdio.dev.fwnode = NULL; + fwnode_handle_put(child); goto clean_phy; } } else if (is_of_node(child)) { |
