From nobody Tue Sep 29 04:42:42 2026 Received: from mta0.migadu.com (out-119.mta0.migadu.com [91.218.175.119]) (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 77D27438495 for ; Wed, 12 Aug 2026 12:52:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.119 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786539126; cv=none; b=KBw/MYzJPE8A8nwpUmcu/2/yic/A35gkEWk8a7HvXYmFH8iRyf8arg8ahD/ntDsZfPKe9a9qSSkH8FEBN16r4mtCLNUbX2pWbbhA9aVS1ZcTsqDwD0yl8TDvcXUKNiiqBtq3Z90+3yExurMG27llm6M89XLJqw/JWVBl8YCcfFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786539126; c=relaxed/simple; bh=cr/4+5Zfa/zkZ85VUOeLYyutNIJ6Hh5yXjA2ZCJ0OjU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gB0EaKWshp2vDRwYLRYXlxWLhVhGugpmZ+BMi33qa9bkGgcoMSAt5uJHgcyN0J5UCy7eRzSlSRqJXzsuf7D5yqwjjuG5iyh8Znrd6Tj8d5UdOx3Lnosgo/q12xb6KLKmQMU7lJp0HBcG80g7Nfu8c7X7YCh2MRskX+51gc33AgU= 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=frDarJV9; arc=none smtp.client-ip=91.218.175.119 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="frDarJV9" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=cr/4+5Zfa/zkZ85VUOeLYyutNIJ6Hh5yXjA2ZCJ0OjU=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786539122; v=1; x=1787143922; b=frDarJV9Qwf757y+7wSa/sBMxYTUS6PjrnzsHFug4JrLX26v76mVbrVVA4If9SAo6KNOIVSH /rqbWwnq5J3XSaY1yTpTk++jbhI0Ozn/sellHPnKBT61cdYpTRV7ZTtn57i56SVBT5j1wMkpNNl ameINcV77aOC5wL4ffSIJkOY= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost.localdomain (116.128.244.171) by smtp.migadu.com with ESMTPS id 8edfd4d755774df5; Wed, 12 Aug 2026 12:52:02 +0000 From: Xuanqiang Luo To: netdev@vger.kernel.org Cc: andrew@lunn.ch, 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 v1 1/2] net: phy: split phy_probe() error paths Date: Wed, 12 Aug 2026 20:51:26 +0800 Message-ID: <20260812125127.106255-2-xuanqiang.luo@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260812125127.106255-1-xuanqiang.luo@linux.dev> References: <20260812125127.106255-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 and leaves phy_setup_ports() relying on its caller to remove an SFP upstream after a partial failure. Make phy_setup_ports() unwind the SFP upstream before removing its ports. Then split the phy_probe() cleanup so each failure path unwinds only the resources that may have been initialized. Signed-off-by: Xuanqiang Luo --- drivers/net/phy/phy_device.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 0615228459ef4..f8e434daab66e 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3556,6 +3556,9 @@ static int phy_setup_ports(struct phy_device *phydev) return 0; =20 out: + sfp_bus_del_upstream(phydev->sfp_bus); + phydev->sfp_bus =3D NULL; + phy_cleanup_ports(phydev); return ret; } @@ -3681,7 +3684,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 +3705,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 +3722,7 @@ static int phy_probe(struct device *dev) =20 err =3D phy_setup_ports(phydev); if (err) - goto out; + goto out_reset; =20 phy_advertise_supported(phydev); =20 @@ -3728,7 +3731,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 +3784,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 04:42:42 2026 Received: from mta0.migadu.com (out-123.mta0.migadu.com [91.218.175.123]) (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 9FCD543F4BA for ; Wed, 12 Aug 2026 12:52:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786539131; cv=none; b=aO3ds5HqBQxZrf14lEOgfkYzNnZolhHTcmlnP6zWnNdP5+hUqtKYcg/AqB6jkPgHLgrlz1LDcfi8rhPbEz3MTXJHExclREwm4DSVxfRrM9DPO/Dl47dZzk+97gHT0Vn2lzx7A4lEMbY9YbUVe+hiPRP4PYl9iKoi4Q+aP3nRdAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786539131; c=relaxed/simple; bh=zQsv1SxLw80HByEkrRnwAzZiBPxpnZQgyvEAyu3vhX4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FNAFFkl4tFkJVZghQJ3F4dOH+N0ZmBrTkg1S/m67XTE7uAC1SW+d0fnVxWlpKq5xFMkmt414qeRXvzFlLQanluwU9UNhk1VA5N558/alrCbH/aqzwffJeBlpWJig/i1Eg4zDH6QGYQR25H2uWQx1l+yY5zwo8nTGEIl1i46d7f8= 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=cG+Hjj9g; arc=none smtp.client-ip=91.218.175.123 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="cG+Hjj9g" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=zQsv1SxLw80HByEkrRnwAzZiBPxpnZQgyvEAyu3vhX4=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786539127; v=1; x=1787143927; b=cG+Hjj9g3BWKmZDP4j0cPIUBsQ7inbl69EOARG/7PZJu++uuBig2cfbSdG7wKSNaE5dmJzLg t+SaZJvKzrhP54tIe9VPqZCiKd6kAsfYCUnVUGkNh2C39qUvKQ/ZJ5L+YzBlctA4KxUR7lee9bR dpfSfn3r+kuAMPmTSbU4oOHg= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost.localdomain (116.128.244.171) by smtp.migadu.com with ESMTPS id 15b4380ad7f88e16; Wed, 12 Aug 2026 12:52:07 +0000 From: Xuanqiang Luo To: netdev@vger.kernel.org Cc: andrew@lunn.ch, 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 v1 2/2] net: phy: call driver remove when core initialization fails Date: Wed, 12 Aug 2026 20:51:27 +0800 Message-ID: <20260812125127.106255-3-xuanqiang.luo@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260812125127.106255-1-xuanqiang.luo@linux.dev> References: <20260812125127.106255-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 f8e434daab66e..be714758360b2 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3705,7 +3705,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)) @@ -3722,7 +3722,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 @@ -3799,6 +3799,10 @@ static int phy_probe(struct device *dev) =20 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