Re: [PATCH net v3 5/5] net: phy: propagate errors from default port setup

From: Maxime Chevallier

Date: Wed Aug 19 2026 - 05:34:22 EST


Hi,

On 8/19/26 08:02, Xuanqiang Luo wrote:
> From: Xuanqiang Luo <luoxuanqiang@xxxxxxxxxx>
>
> 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.
>
> Fixes: 589e934d2735 ("net: phy: Introduce PHY ports representation")
> Signed-off-by: Xuanqiang Luo <luoxuanqiang@xxxxxxxxxx>

Reviewed-by: Maxime Chevallier <maxime.chevallier@xxxxxxxxxxx

Maxime

> ---
> drivers/net/phy/phy_device.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 77318659ff985..22a5af92c620a 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -3458,6 +3458,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;
> @@ -3484,9 +3485,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)