linux/net/dsa
Vladimir Oltean baf4504771 net: dsa: destroy the phylink instance on any error in dsa_slave_phy_setup
commit 6a52e73368038f47f6618623d75061dc263b26ae 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: aab9c4067d ("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>
2021-09-22 12:26:42 +02:00
..
Kconfig net: dsa: add GRO support via gro_cells 2021-03-11 14:06:48 +01:00
Makefile
dsa.c net: dsa: add GRO support via gro_cells 2021-03-11 14:06:48 +01:00
dsa2.c
dsa_priv.h net: dsa: add GRO support via gro_cells 2021-03-11 14:06:48 +01:00
master.c net: dsa: fix a crash if ->get_sset_count() fails 2021-06-03 08:59:07 +02:00
port.c
slave.c net: dsa: destroy the phylink instance on any error in dsa_slave_phy_setup 2021-09-22 12:26:42 +02:00
switch.c
tag_8021q.c
tag_brcm.c
tag_dsa.c
tag_edsa.c
tag_gswip.c
tag_ksz.c
tag_lan9303.c
tag_mtk.c net: dsa: tag_mtk: fix 802.1ad VLAN egress 2021-03-20 10:39:47 +01:00
tag_qca.c
tag_sja1105.c
tag_trailer.c