From nobody Tue Sep 29 01:56:50 2026 Received: from mta0.migadu.com (out-26.mta0.migadu.com [91.218.175.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65E6947ECEB for ; Thu, 13 Aug 2026 13:30:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.26 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786627811; cv=none; b=BpdDSYSnw/R02WZQEV0wP2TX2drWztDHyIzjGinq/dif34KWbE1vF2Avq7vEgxWTfWx/YEr4OS4jU+1F/BhJCG3AEXm4kOOw0xFywvYHTwlGyEQtbja1OMsPPG8QzJNVE1WDVqbxisgWcyN4HrRCI39hFabfQbZt0MgPX5cc3jE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786627811; c=relaxed/simple; bh=CL0N8elDQ4wwTZ4RkCqCpiUMNIVZK9/qKZ0kQM8xFgg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ohE/3HtSvkRaUgiyL5jYymYIMmeUGcf+INMg5CnJJ0fYF0TTigSrVIcv3wza8+5tILcMVG0FZRkcL31qO/y5VGChr42KSnRvqhICRfidNkwvnyZpMAUn0cCf8JX2SXwAyT04IZkmmYrow3jJWdOFGY3Pj0gyJAq/BWRaJ9SQLb4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=FaMopyxB; arc=none smtp.client-ip=91.218.175.26 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="FaMopyxB" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=CL0N8elDQ4wwTZ4RkCqCpiUMNIVZK9/qKZ0kQM8xFgg=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786627808; v=1; x=1787232608; b=FaMopyxBWJhUH2slXW/Bh20t0m0FYV9yI+/MEwHZPDXuTmby24TY4BalAerAi4EoV1k6zeg2 yUZepPf2noy2/7MSODzJ+C3BTaf9H2qtO7dPh6c3or9YDkyXuhBTRSPLmhns9lARxzg4DmmqdE/ Irn8fjSip6XNn5v/0TIodxCE= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost.localdomain (116.128.244.171) by smtp.migadu.com with ESMTPS id 88ccd6f65087217c; Thu, 13 Aug 2026 13:30:08 +0000 X-Migadu-Flow: FLOW_OUT From: Xuanqiang Luo To: netdev@vger.kernel.org, andrew@lunn.ch, maxime.chevallier@bootlin.com Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, Xuanqiang Luo Subject: [PATCH net v2 1/5] net: phy: split phy_probe() error paths Date: Thu, 13 Aug 2026 21:29:41 +0800 Message-ID: <20260813132946.116176-2-xuanqiang.luo@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260813132946.116176-1-xuanqiang.luo@linux.dev> References: <20260813132946.116176-1-xuanqiang.luo@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xuanqiang Luo phy_probe() uses one cleanup path for failures at every initialization stage. This runs cleanup for resources that have not been initialized. Split the cleanup by initialization stage so each failure path unwinds only the resources that may have been initialized. Signed-off-by: Xuanqiang Luo --- drivers/net/phy/phy_device.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 0615228459ef4..c9976ffa7128c 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3681,7 +3681,7 @@ static int phy_probe(struct device *dev) if (phydev->drv->probe) { err =3D phydev->drv->probe(phydev); if (err) - goto out; + goto out_reset; } =20 phy_disable_interrupts(phydev); @@ -3702,7 +3702,7 @@ static int phy_probe(struct device *dev) err =3D genphy_read_abilities(phydev); =20 if (err) - goto out; + goto out_reset; =20 if (!linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->supported)) @@ -3719,7 +3719,7 @@ static int phy_probe(struct device *dev) =20 err =3D phy_setup_ports(phydev); if (err) - goto out; + goto out_ports; =20 phy_advertise_supported(phydev); =20 @@ -3728,7 +3728,7 @@ static int phy_probe(struct device *dev) */ err =3D genphy_c45_read_eee_adv(phydev, phydev->advertising_eee); if (err) - goto out; + goto out_ports; =20 /* Get the EEE modes we want to prohibit. */ of_set_phy_eee_broken(phydev); @@ -3781,20 +3781,22 @@ static int phy_probe(struct device *dev) if (IS_ENABLED(CONFIG_PHYLIB_LEDS) && !phy_driver_is_genphy(phydev)) { err =3D of_phy_leds(phydev); if (err) - goto out; + goto out_led_triggers; } =20 return 0; =20 -out: +out_led_triggers: + if (!phydev->is_on_sfp_module) + phy_led_triggers_unregister(phydev); + +out_ports: sfp_bus_del_upstream(phydev->sfp_bus); phydev->sfp_bus =3D NULL; =20 phy_cleanup_ports(phydev); =20 - if (!phydev->is_on_sfp_module) - phy_led_triggers_unregister(phydev); - +out_reset: /* Re-assert the reset signal on error */ phy_device_reset(phydev, 1); =20 --=20 2.43.0 From nobody Tue Sep 29 01:56:50 2026 Received: from mta0.migadu.com (out-28.mta0.migadu.com [91.218.175.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DAE0D47ECD0 for ; Thu, 13 Aug 2026 13:30:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.28 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786627816; cv=none; b=YZ1S6x5BjU9RUoPBqKvRspPqXCcEswulca0Bkf4vTjHGu4E63QxQjoUbt7WmNlu2h7UYEJ4oVE3ppFfuoEMQHxp9evwtZhesXdUaBM5clmbo9r92MGb7+8BmeFweTUv1073UyQOmQJ05WAmd1sNbfyJ03cIQw95/gCDJwtONIGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786627816; c=relaxed/simple; bh=lq25oIu9+o+ffSjW1NcfTAHgbjcyHjlkGa5P9ei4HLQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fdN+ihfjWTdM3pgOEGjNjNK4iYGfWAgwEPvOdo9CUnGrFhpKk3Bf6sV4/RDtJGp2JPAce3beNxOHKLukU3eKj8J8bRKzTwRnB3dblma0Fg68y+tXwuY7jPo1qlao27M+ceeTaL/dgQuaxWMIIq70ufLRBT58Infn6CmP5W7J/4E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=nnVPnsb+; arc=none smtp.client-ip=91.218.175.28 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="nnVPnsb+" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=lq25oIu9+o+ffSjW1NcfTAHgbjcyHjlkGa5P9ei4HLQ=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786627812; v=1; x=1787232612; b=nnVPnsb+04zYXDznLGHMi5p1vqZ6kx9rX+Hld+6JHhdcP+Cw6+mtlKo+RUijItf4mMdBOVXP rHuOKy3XV2TmuDvMEfG0Z0fphTdUKcQ7mwcwZJsEsMah/jYKJe4M+IOXHQ1R2xoELTXEdNIvze3 zDX4u2w8SdkPeu33TbAFyf8w= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost.localdomain (116.128.244.171) by smtp.migadu.com with ESMTPS id 025b893fb563e32c; Thu, 13 Aug 2026 13:30:12 +0000 X-Migadu-Flow: FLOW_OUT From: Xuanqiang Luo To: netdev@vger.kernel.org, andrew@lunn.ch, maxime.chevallier@bootlin.com Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, Xuanqiang Luo Subject: [PATCH net v2 2/5] net: phy: unregister SFP upstream before port cleanup Date: Thu, 13 Aug 2026 21:29:42 +0800 Message-ID: <20260813132946.116176-3-xuanqiang.luo@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260813132946.116176-1-xuanqiang.luo@linux.dev> References: <20260813132946.116176-1-xuanqiang.luo@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xuanqiang Luo Commit 4497f5028675 ("net: phy: Clean the phy_ports after unregistering the downstream SFP bus") established that an SFP upstream must be unregistered before its phy_ports are destroyed because SFP callbacks may access these ports. phy_setup_ports() does not follow this order when a later port setup step fails after phy_sfp_probe() succeeds. It destroys the SFP phy_port and leaves phy_probe() to unregister the upstream later, creating a race between port destruction and SFP upstream callbacks. The error unwind is also split across three functions. If phy_setup_sfp_port() fails, phy_sfp_probe() leaves the upstream registered and relies on phy_probe() to remove it after phy_setup_ports() returns. Make each layer unwind the resources it successfully set up. Unregister only the upstream in phy_sfp_probe() when SFP port setup fails, since the failed port has already been destroyed. Add phy_sfp_release() for a successful SFP probe, and make phy_setup_ports() use it before cleaning up the remaining ports. Once phy_setup_ports() has rolled back all port setup, make phy_probe() skip this cleanup. Fixes: 589e934d2735 ("net: phy: Introduce PHY ports representation") Signed-off-by: Xuanqiang Luo --- drivers/net/phy/phy_device.c | 49 ++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index c9976ffa7128c..9c7ed9c61e6d5 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1723,12 +1723,41 @@ static int phy_sfp_probe(struct phy_device *phydev) phydev->sfp_bus =3D NULL; } =20 - if (!ret && phydev->sfp_bus) + if (!ret && phydev->sfp_bus) { ret =3D phy_setup_sfp_port(phydev); + if (ret) { + sfp_bus_del_upstream(phydev->sfp_bus); + phydev->sfp_bus =3D NULL; + } + } =20 return ret; } =20 +/** + * phy_sfp_release - release resources set up by phy_sfp_probe() + * @phydev: the PHY device + * + * Release the SFP resources set up by a successful phy_sfp_probe(). Unreg= ister + * the upstream before destroying its phy_port, so SFP upstream callbacks = cannot + * race with port destruction. + */ +static void phy_sfp_release(struct phy_device *phydev) +{ + struct phy_port *port, *tmp; + + sfp_bus_del_upstream(phydev->sfp_bus); + phydev->sfp_bus =3D NULL; + + list_for_each_entry_safe(port, tmp, &phydev->ports, head) { + if (!port->is_sfp) + continue; + + phy_del_port(phydev, port); + phy_port_destroy(port); + } +} + static bool phy_drv_supports_irq(const struct phy_driver *phydrv) { return phydrv->config_intr && phydrv->handle_interrupt; @@ -3522,13 +3551,13 @@ static int phy_setup_ports(struct phy_device *phyde= v) if (!phydev->is_genphy_driven) { ret =3D phy_sfp_probe(phydev); if (ret) - goto out; + goto err_ports; } =20 if (phydev->n_ports < phydev->max_n_ports) { ret =3D phy_default_setup_single_port(phydev); if (ret) - goto out; + goto err_sfp; } =20 linkmode_zero(ports_supported); @@ -3555,7 +3584,9 @@ static int phy_setup_ports(struct phy_device *phydev) =20 return 0; =20 -out: +err_sfp: + phy_sfp_release(phydev); +err_ports: phy_cleanup_ports(phydev); return ret; } @@ -3719,7 +3750,7 @@ static int phy_probe(struct device *dev) =20 err =3D phy_setup_ports(phydev); if (err) - goto out_ports; + goto out_reset; =20 phy_advertise_supported(phydev); =20 @@ -3791,9 +3822,7 @@ static int phy_probe(struct device *dev) phy_led_triggers_unregister(phydev); =20 out_ports: - sfp_bus_del_upstream(phydev->sfp_bus); - phydev->sfp_bus =3D NULL; - + phy_sfp_release(phydev); phy_cleanup_ports(phydev); =20 out_reset: @@ -3817,9 +3846,7 @@ static int phy_remove(struct device *dev) =20 phydev->state =3D PHY_DOWN; =20 - sfp_bus_del_upstream(phydev->sfp_bus); - phydev->sfp_bus =3D NULL; - + phy_sfp_release(phydev); phy_cleanup_ports(phydev); =20 if (phydev->drv && phydev->drv->remove) --=20 2.43.0 From nobody Tue Sep 29 01:56:50 2026 Received: from mta1.migadu.com (out-147.mta1.migadu.com [95.215.58.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BDAB4749C8 for ; Thu, 13 Aug 2026 13:30:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786627825; cv=none; b=cyBlLp6DRji6NJhWF8Fv36bWglPWezTpaFOaplS8QhKiLv7nadAtNQP1AjXV/fXrBSa5IcPAO2YJLiimwC9x1qjKyFw6iOpvtu8sOfCu76ZI594gQErax6aABnAUuOoadGP+wv0dpw4qk/erE/fV3ae3HvahUhPV4kSW8N1vInk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786627825; c=relaxed/simple; bh=84ItSrTAzDge5vQVE0g9FnTODG6xfS9Fw3jEzj4j7/M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hfq0mIoFWkwFrvpb8edpUX1rueq/W7J9k7F20qJxqRFpEVE9GjZkFM/iC2GkSoyA41NACUi0NfPsfVquorqNHm+9cP35PyvV4lKCrQzfmtgWsxpcdgPHf1CqqcOUJrrnMiSbDEYaClw9l+XOCxoTs58I4Jf/2Uuc8Oje2D+gqQ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=RqhaRfda; arc=none smtp.client-ip=95.215.58.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="RqhaRfda" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=84ItSrTAzDge5vQVE0g9FnTODG6xfS9Fw3jEzj4j7/M=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786627821; v=1; x=1787232621; b=RqhaRfdaM9G2P6dJH2Pb5jbXUvml+V2Jc686CotHuVzy8Ss8svUXn0c6j1FbWcpUPNbA0TNb PU9/rLhw++fBg0L3WvcG9LrRzFraldAqmGlXIJx1CX8hSJZip8061/scPpGs8hFB0hU0CVLUPwD gg844TYbuGGVgru6ca/CJMvU= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost.localdomain (116.128.244.171) by smtp.migadu.com with ESMTPS id 170d6f0a33b4d479; Thu, 13 Aug 2026 13:30:21 +0000 X-Migadu-Flow: FLOW_OUT From: Xuanqiang Luo To: netdev@vger.kernel.org, andrew@lunn.ch, maxime.chevallier@bootlin.com Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, Xuanqiang Luo Subject: [PATCH net v2 3/5] net: phy: restore device state after probe failure Date: Thu, 13 Aug 2026 21:29:43 +0800 Message-ID: <20260813132946.116176-4-xuanqiang.luo@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260813132946.116176-1-xuanqiang.luo@linux.dev> References: <20260813132946.116176-1-xuanqiang.luo@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xuanqiang Luo phy_probe() sets phydev->drv before calling the PHY driver probe callback, but does not clear it if probing later fails. It also sets PHY_READY before of_phy_leds(), leaving the state ready if LED setup fails. Clear phydev->drv on every error path and restore PHY_DOWN after LED setup failure. Fixes: 00db8189d984 ("This patch adds a PHY Abstraction Layer to the Linux = Kernel, enabling ethernet drivers to remain as ignorant as is reasonable of= the connected PHY's design and operation details.") Signed-off-by: Xuanqiang Luo --- drivers/net/phy/phy_device.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 9c7ed9c61e6d5..c9e75bd3b81a2 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3821,6 +3821,8 @@ static int phy_probe(struct device *dev) if (!phydev->is_on_sfp_module) phy_led_triggers_unregister(phydev); =20 + phydev->state =3D PHY_DOWN; + out_ports: phy_sfp_release(phydev); phy_cleanup_ports(phydev); @@ -3828,6 +3830,7 @@ static int phy_probe(struct device *dev) out_reset: /* Re-assert the reset signal on error */ phy_device_reset(phydev, 1); + phydev->drv =3D NULL; =20 return err; } --=20 2.43.0 From nobody Tue Sep 29 01:56:50 2026 Received: from mta0.migadu.com (out-37.mta0.migadu.com [91.218.175.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E610147D92C for ; Thu, 13 Aug 2026 13:30:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786627833; cv=none; b=bs16upR2dbO+xl3/Ypdk6moKCDjXViRRGZHXRsA2EnV+s9dVcV+dpNEnvncXtcawn7srmPIPEUHu7GdLjuMAJ5iUsKLMVbtkCgc67BEwAD4o7uic3DSQUfuXigmXk/l4v5WuFzgXb/TYb8hM6a64ioJto7PMniAVIIc17rI37Hg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786627833; c=relaxed/simple; bh=0vlOCpYNZjGLKJXhXKNPZlQoO53c/wGY2T+lT0zR1rs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tcaWbPcVEV1ZBkevKnZzBEcRAAkQx0yyBK63+0GbEMquAn+PCCvPSdhmiKWdLx0nV2/OvV8knXnVDBUQue/bhohX5E67aWVuOHTTzetsMRdsUKfmSH3hpFhsHCO/E+MRcfG/wnxoNW2yMIFLnh1UftPsqyMErJk/zmWHegAHdWc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=nYM4lutw; arc=none smtp.client-ip=91.218.175.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="nYM4lutw" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=0vlOCpYNZjGLKJXhXKNPZlQoO53c/wGY2T+lT0zR1rs=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786627829; v=1; x=1787232629; b=nYM4lutw2XIpw7/VHM/l/0bUUYXXWCt/ePr5z3t8CYYrOvEHYvh+sEkyHOdTazgbTtTiKnj5 DEHx60ZmNV1zwFcxMROQiYJhcdV75u7mAXNhDFvfI5NxetAl1JvOai2HczPJT3vQnWh6OSo35FI kWEOefCH21tL2kBFNbDR/GWo= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost.localdomain (116.128.244.171) by smtp.migadu.com with ESMTPS id a87847907bbed906; Thu, 13 Aug 2026 13:30:29 +0000 X-Migadu-Flow: FLOW_OUT From: Xuanqiang Luo To: netdev@vger.kernel.org, andrew@lunn.ch, maxime.chevallier@bootlin.com Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, Xuanqiang Luo Subject: [PATCH net v2 4/5] net: phy: call driver remove when core initialization fails Date: Thu, 13 Aug 2026 21:29:44 +0800 Message-ID: <20260813132946.116176-5-xuanqiang.luo@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260813132946.116176-1-xuanqiang.luo@linux.dev> References: <20260813132946.116176-1-xuanqiang.luo@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xuanqiang Luo phy_probe() may fail while querying features or completing other core initialization after the PHY driver probe callback has succeeded. The driver core does not run the remove path after a probe error, so resources that the PHY driver releases in its remove callback are leaked. Call the PHY driver remove callback on these failures. Fixes: efbdfdc29bdd ("net: phy: Add support for asking the PHY its abilitie= s") Signed-off-by: Xuanqiang Luo --- drivers/net/phy/phy_device.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index c9e75bd3b81a2..e429e6d702933 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3733,7 +3733,7 @@ static int phy_probe(struct device *dev) err =3D genphy_read_abilities(phydev); =20 if (err) - goto out_reset; + goto out_remove; =20 if (!linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->supported)) @@ -3750,7 +3750,7 @@ static int phy_probe(struct device *dev) =20 err =3D phy_setup_ports(phydev); if (err) - goto out_reset; + goto out_remove; =20 phy_advertise_supported(phydev); =20 @@ -3827,6 +3827,10 @@ static int phy_probe(struct device *dev) phy_sfp_release(phydev); phy_cleanup_ports(phydev); =20 +out_remove: + if (phydev->drv->remove) + phydev->drv->remove(phydev); + out_reset: /* Re-assert the reset signal on error */ phy_device_reset(phydev, 1); --=20 2.43.0 From nobody Tue Sep 29 01:56:50 2026 Received: from mta0.migadu.com (out-42.mta0.migadu.com [91.218.175.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 567F647604A for ; Thu, 13 Aug 2026 13:30:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786627837; cv=none; b=CaDXmztzVgfLdcYyrd3qvwsWpmpXeMx5PlErWo5TtQCEzNIksvC2nzL9gyuCFE8lDK/A8r3UQTA5sCehbasq3PULZaySazt8HWN9a8UUyIiMSumfTlCzS+ooinoNIXDGW1XOiQwnFskt2Nqld3pqmrOLOlj9mVhRCpjoPb/+wMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786627837; c=relaxed/simple; bh=Nudt+IbkfkwauE6dUG3bv1rneSe/FGDN28GDWLG9XsU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DLctaus2LlnsbrXFV7sDZ7Ba2kOEpRdSXr+iWo3Ro7ZQP2/PTnIwEhAG3m2b/LDOOet0lJqW8FAjbIgfizkoOpuXh2Lpq2U4sSmiq34JtLNZoMGZnAxyVrAGaKsrAg1+7JkwiZIi47HI4GFmoOV8WVuqaBKhrnDhwdsTvrgWIq0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Zpa1zCa6; arc=none smtp.client-ip=91.218.175.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Zpa1zCa6" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=Nudt+IbkfkwauE6dUG3bv1rneSe/FGDN28GDWLG9XsU=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786627834; v=1; x=1787232634; b=Zpa1zCa67sTsaAbldjGVJ8DiVZCwwB3MyeARtAD6F2Ndt1MgEY5Wj0d98WFY7WC4K4SPmGf5 GYaRiTy+7zxF2kAJkRfDiCpBA6VTzISrpV0ygDLi8XRh8BhD26chM95FCfaCmtAnsaRvDV08hwo Jlyg/Cw9+Zw2cdI9pqrFLqNE= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost.localdomain (116.128.244.171) by smtp.migadu.com with ESMTPS id 135311f7978a6c62; Thu, 13 Aug 2026 13:30:34 +0000 X-Migadu-Flow: FLOW_OUT From: Xuanqiang Luo To: netdev@vger.kernel.org, andrew@lunn.ch, maxime.chevallier@bootlin.com Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, Xuanqiang Luo Subject: [PATCH net v2 5/5] net: phy: propagate errors from default port setup Date: Thu, 13 Aug 2026 21:29:45 +0800 Message-ID: <20260813132946.116176-6-xuanqiang.luo@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260813132946.116176-1-xuanqiang.luo@linux.dev> References: <20260813132946.116176-1-xuanqiang.luo@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xuanqiang Luo 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 --- 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 e429e6d702933..b0060b4147348 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_d= evice *phydev) { struct phy_port *port =3D phy_port_alloc(); unsigned long mode; + int ret; =20 if (!port) return -ENOMEM; @@ -3484,9 +3485,11 @@ static int phy_default_setup_single_port(struct phy_= device *phydev) port->pairs =3D max_t(int, port->pairs, ethtool_linkmode_n_pairs(mode)); =20 - phy_add_port(phydev, port); + ret =3D phy_add_port(phydev, port); + if (ret) + phy_port_destroy(port); =20 - return 0; + return ret; } =20 static int of_phy_ports(struct phy_device *phydev) --=20 2.43.0