提交 099b1924 编写于 作者: V Vladimir Oltean 提交者: Zheng Zengkai

net: dsa: destroy the phylink instance on any error in dsa_slave_phy_setup

stable inclusion
from stable-5.10.68
commit cf6f29bb2c18be0aaa54d85b5d58f6a9759bcbf1
bugzilla: 182671 https://gitee.com/openeuler/kernel/issues/I4EWUH

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=cf6f29bb2c18be0aaa54d85b5d58f6a9759bcbf1

--------------------------------

commit 6a52e733 upstream.

DSA supports connecting to a phy-handle, and has a fallback to a non-OF
based method of connecting to an internal PHY on the switch's own MDIO
bus, if no phy-handle and no fixed-link nodes were present.

The -ENODEV error code from the first attempt (phylink_of_phy_connect)
is what triggers the second attempt (phylink_connect_phy).

However, when the first attempt returns a different error code than
-ENODEV, this results in an unbalance of calls to phylink_create and
phylink_destroy by the time we exit the function. The phylink instance
has leaked.

There are many other error codes that can be returned by
phylink_of_phy_connect. For example, phylink_validate returns -EINVAL.
So this is a practical issue too.

Fixes: aab9c406 ("net: dsa: Plug in PHYLINK support")
Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: NFlorian Fainelli <f.fainelli@gmail.com>
Reviewed-by: NRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://lore.kernel.org/r/20210914134331.2303380-1-vladimir.oltean@nxp.comSigned-off-by: NJakub Kicinski <kuba@kernel.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: NWeilong Chen <chenweilong@huawei.com>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 7b9ccfab
...@@ -1728,13 +1728,11 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev) ...@@ -1728,13 +1728,11 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
* use the switch internal MDIO bus instead * use the switch internal MDIO bus instead
*/ */
ret = dsa_slave_phy_connect(slave_dev, dp->index); ret = dsa_slave_phy_connect(slave_dev, dp->index);
if (ret) { }
netdev_err(slave_dev, if (ret) {
"failed to connect to port %d: %d\n", netdev_err(slave_dev, "failed to connect to PHY: %pe\n",
dp->index, ret); ERR_PTR(ret));
phylink_destroy(dp->pl); phylink_destroy(dp->pl);
return ret;
}
} }
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册