net: phy: propagate errors from default port setup

phy_default_setup_single_port() ignores errors from phy_add_port() and
always reports success. If a PHY driver attach_mdi_port() callback fails,
the phy_port is leaked and PHY probing continues without the expected
default port.

Destroy the port and return the error.

Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
Link: https://patch.msgid.link/20260823035600.188864-6-xuanqiang.luo@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Xuanqiang Luo 2026-08-23 11:55:59 +08:00 committed by Jakub Kicinski
parent afd5aecd3c
commit 48378efebb

View File

@ -3483,6 +3483,7 @@ static int phy_default_setup_single_port(struct phy_device *phydev)
{
struct phy_port *port = phy_port_alloc();
unsigned long mode;
int ret;
if (!port)
return -ENOMEM;
@ -3509,9 +3510,11 @@ static int phy_default_setup_single_port(struct phy_device *phydev)
port->pairs = max_t(int, port->pairs,
ethtool_linkmode_n_pairs(mode));
phy_add_port(phydev, port);
ret = phy_add_port(phydev, port);
if (ret)
phy_port_destroy(port);
return 0;
return ret;
}
static int of_phy_ports(struct phy_device *phydev)