Skip to content

Commit cf6f29b

Browse files
vladimirolteangregkh
authored andcommitted
net: dsa: destroy the phylink instance on any error in dsa_slave_phy_setup
commit 6a52e73 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: aab9c40 ("net: dsa: Plug in PHYLINK support") Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Link: https://lore.kernel.org/r/20210914134331.2303380-1-vladimir.oltean@nxp.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent df38f94 commit cf6f29b

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

‎net/dsa/slave.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,13 +1728,11 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
17281728
* use the switch internal MDIO bus instead
17291729
*/
17301730
ret = dsa_slave_phy_connect(slave_dev, dp->index);
1731-
if (ret) {
1732-
netdev_err(slave_dev,
1733-
"failed to connect to port %d: %d\n",
1734-
dp->index, ret);
1735-
phylink_destroy(dp->pl);
1736-
return ret;
1737-
}
1731+
}
1732+
if (ret) {
1733+
netdev_err(slave_dev, "failed to connect to PHY: %pe\n",
1734+
ERR_PTR(ret));
1735+
phylink_destroy(dp->pl);
17381736
}
17391737

17401738
return ret;

0 commit comments

Comments
 (0)