Commit 94423589 authored by Yang Yingliang's avatar Yang Yingliang Committed by Jakub Kicinski

net: netsec: fix error handling in netsec_register_mdio()

If phy_device_register() fails, phy_device_free() need be called to
put refcount, so memory of phy device and device name can be freed
in callback function.

If get_phy_device() fails, mdiobus_unregister() need be called,
or it will cause warning in mdiobus_free() and kobject is leaked.

Fixes: 533dd11a ("net: socionext: Add Synquacer NetSec driver")
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20221019064104.3228892-1-yangyingliang@huawei.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 82cb4e46
...@@ -1961,11 +1961,13 @@ static int netsec_register_mdio(struct netsec_priv *priv, u32 phy_addr) ...@@ -1961,11 +1961,13 @@ static int netsec_register_mdio(struct netsec_priv *priv, u32 phy_addr)
ret = PTR_ERR(priv->phydev); ret = PTR_ERR(priv->phydev);
dev_err(priv->dev, "get_phy_device err(%d)\n", ret); dev_err(priv->dev, "get_phy_device err(%d)\n", ret);
priv->phydev = NULL; priv->phydev = NULL;
mdiobus_unregister(bus);
return -ENODEV; return -ENODEV;
} }
ret = phy_device_register(priv->phydev); ret = phy_device_register(priv->phydev);
if (ret) { if (ret) {
phy_device_free(priv->phydev);
mdiobus_unregister(bus); mdiobus_unregister(bus);
dev_err(priv->dev, dev_err(priv->dev,
"phy_device_register err(%d)\n", ret); "phy_device_register err(%d)\n", ret);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment