]> git.baikalelectronics.ru Git - kernel.git/commit
net: dsa: destroy the phylink instance on any error in dsa_slave_phy_setup
authorVladimir Oltean <vladimir.oltean@nxp.com>
Tue, 14 Sep 2021 13:43:31 +0000 (16:43 +0300)
committerJakub Kicinski <kuba@kernel.org>
Wed, 15 Sep 2021 22:03:36 +0000 (15:03 -0700)
commit996365bf1af382e86d9fbdb238c313fae2979cbb
treeac6a10ada0817a9c9f979350a31efcbca7a84f1f
parent68b5a3991991450ea19074df35d109a4cab7ad47
net: dsa: destroy the phylink instance on any error in dsa_slave_phy_setup

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: a81bccb0d343 ("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>
net/dsa/slave.c