From nobody Mon Sep 28 18:33:29 2026 Received: from mta0.migadu.com (out-136.mta0.migadu.com [91.218.175.136]) (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 B48463CB8FC for ; Wed, 19 Aug 2026 06:02:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.136 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787119377; cv=none; b=iL5WO2bmTgx7Noq6wJ92z76VOl7Qvd6m1hGWQ9VyHYfVyYbU2i2PXOIEH6Sh+UY50F0Whr6y8jS+/xZU1uNMUmyFPUjczKjOzvbFLhz0qGnifg5RM+qfi+h6jxWO4fjkB7+oBPAAk3HMnnRcYlRVaHsllQC+CxhYUnnCAma2S9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787119377; c=relaxed/simple; bh=WeqA8pFD0+VEJMYtafd904AuzYUQopOTlTrjheK8V1s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bh7bxe/P8KCT3PFJPZNI787kiSaoS6MT0kHt7TQbz7CJkbtlditr73XjCN/sRQwYjk60YC5x1sdqEWJYBHiykUljXlVz1Id2VEN3rkRHoaRWou2OkivJ48DRJyUBHRBfqRH5ernY2on5aWN2wOlsRQnQaMAFytv5DxY1WVo1HME= 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=Th9ZCjyd; arc=none smtp.client-ip=91.218.175.136 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="Th9ZCjyd" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=WeqA8pFD0+VEJMYtafd904AuzYUQopOTlTrjheK8V1s=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787119373; v=1; x=1787724173; b=Th9ZCjydeBxeSrKNxgITE2sykRaV4hBevY26gPhgg+8acNDzEYQN5FC3I7L7rEASnATgct6j 8mZBJFEO2hJj93Cb1AGl3zoe5i/eQ3mQOvYNgslY9RDyR5H4gsWEccu3e1xP5zlatS5+2FqWn1t lJQlDYqhYnF8G6MihHN0sZpg= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost.localdomain (116.128.244.171) by smtp.migadu.com with ESMTPS id a3addec7ac238d5d; Wed, 19 Aug 2026 06:02:53 +0000 X-Migadu-Flow: FLOW_OUT From: Xuanqiang Luo To: netdev@vger.kernel.org, kuba@kernel.org, andrew@lunn.ch, maxime.chevallier@bootlin.com Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, chleroy@kernel.org, linux-kernel@vger.kernel.org, Xuanqiang Luo Subject: [PATCH net v3 1/5] net: phy: split phy_probe() error paths Date: Wed, 19 Aug 2026 14:02:32 +0800 Message-ID: <20260819060236.24665-2-xuanqiang.luo@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819060236.24665-1-xuanqiang.luo@linux.dev> References: <20260819060236.24665-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..59ee5a76af2ba 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_sfp_release; =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_sfp_release; =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_unreg_led_triggers; } =20 return 0; =20 -out: +out_unreg_led_triggers: + if (!phydev->is_on_sfp_module) + phy_led_triggers_unregister(phydev); + +out_sfp_release: 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 Mon Sep 28 18:33:29 2026 Received: from mta1.migadu.com (out-151.mta1.migadu.com [95.215.58.151]) (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 82AA8280331 for ; Wed, 19 Aug 2026 06:03:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787119385; cv=none; b=o7CSEyOWTjrzgkhknowjkRlJBHmxMkD0+sOO2+XEyU+7U+ndcpWrqdDrmwQqqMAngcjkWoyW3kLmtna8eaYXwD08ikWCcHOggJY/SPTq9efsLivkLE2seYLk0zfofoAx1JbVDK7jxt0wpUz1d5S+2u9+Hu+qAuP4GIxPun0iQ1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787119385; c=relaxed/simple; bh=/hlDrhU2v9TGXsg6MNSxhtxz8k/cV1tZgnyIOxl3bkI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gqr2JYxibawSgwfBV7MSnNpcyYa7mA4rgh0hAcbjWbqommNvVupxVah3HMJB+8rO4L1vTmgDMHjJ7mrGop7kyFctnX1jHIR5hHYNRegzhdEYkINjj+0ZA2ICJBbH/dpHqwqVs0KOIYhhBsxNL3gaQlB9m+aVesHGtL+ciTnrFEg= 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=CLFYp7mF; arc=none smtp.client-ip=95.215.58.151 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="CLFYp7mF" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=/hlDrhU2v9TGXsg6MNSxhtxz8k/cV1tZgnyIOxl3bkI=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787119381; v=1; x=1787724181; b=CLFYp7mFhAq91QiJQluO2rP6VRfA6gLbII3ss+iZjBtMaiCaxxn/jok8bLF6Z7brUZwT6qZ7 mxMs6ZeLQtagaibb2+rxbyPmofw/C5EBTKPxXm+n9UsEGDtd3oXQ9ul8haU3zYGSxes/Hc9ao9q hHesnT5VIL8ofX0/1Cu5pJSw= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost.localdomain (116.128.244.171) by smtp.migadu.com with ESMTPS id 88d3608cbd2aacfa; Wed, 19 Aug 2026 06:03:01 +0000 X-Migadu-Flow: FLOW_OUT From: Xuanqiang Luo To: netdev@vger.kernel.org, kuba@kernel.org, andrew@lunn.ch, maxime.chevallier@bootlin.com Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, chleroy@kernel.org, linux-kernel@vger.kernel.org, Xuanqiang Luo Subject: [PATCH net v3 2/5] net: phy: unregister SFP upstream before port cleanup Date: Wed, 19 Aug 2026 14:02:33 +0800 Message-ID: <20260819060236.24665-3-xuanqiang.luo@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819060236.24665-1-xuanqiang.luo@linux.dev> References: <20260819060236.24665-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 Reviewed-by: Andrew Lunn --- 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 59ee5a76af2ba..538e9ca44d093 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_sfp_release; + 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_sfp_release: - 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 Mon Sep 28 18:33:29 2026 Received: from mta1.migadu.com (out-154.mta1.migadu.com [95.215.58.154]) (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 201583CB547 for ; Wed, 19 Aug 2026 06:03:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787119391; cv=none; b=WKMKPcWVO8WDtISrh75RkWvDLLQpu0kSUxNn83vxlAHdRuveBfEOCfW04mqHhRZE03Tq5KU5bxy8aFmOM7H1mVwnkKnyDUTNDXkjZs+uDe+nO/+kXnQWfn7m1ImG7tjOQr1vn66VTT9wjt8KHsgKFnlXdNQEY/USsrs5hrMSTrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787119391; c=relaxed/simple; bh=7fd8iX7HvFHjWIPbWAckzSULKH2drvaBAS9xUkB+rj8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HPOV3CGeSFRhYR/PJVV0Jcb9T9MEA455lgwh4c0e2DpuGcfJmW/QP8k/9nY8Wdwjuc/UqgoBrzdtiFvz4PLpV3WEnS/4+z5yHqUbvwmWsVbDsoQ907Wh7+g5R8MBrXpFgXnr+UOotthc9ZwGEC1vf4gs8nXANHNe4msDz8/+A/c= 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=Sd3l4GRV; arc=none smtp.client-ip=95.215.58.154 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="Sd3l4GRV" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=7fd8iX7HvFHjWIPbWAckzSULKH2drvaBAS9xUkB+rj8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787119388; v=1; x=1787724188; b=Sd3l4GRVI+TDrTAetIGkc+mllJTQMMDXutwCIkueh29suHkW9RmcmExZAdcQDoP2bn0XHU7Z CqO6NH/ydZxwiyn8OzEC9LHSyAQv6ABvWvXjFqstxzXmTCcLqPhCP1hbFqKdmBPi4Y0zNt5d9DG LWQgMF/dJS1WD2L0voEeQO6Y= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost.localdomain (116.128.244.171) by smtp.migadu.com with ESMTPS id 896faae294527483; Wed, 19 Aug 2026 06:03:07 +0000 X-Migadu-Flow: FLOW_OUT From: Xuanqiang Luo To: netdev@vger.kernel.org, kuba@kernel.org, andrew@lunn.ch, maxime.chevallier@bootlin.com Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, chleroy@kernel.org, linux-kernel@vger.kernel.org, Xuanqiang Luo Subject: [PATCH net v3 3/5] net: phy: set PHY_READY after LED setup Date: Wed, 19 Aug 2026 14:02:34 +0800 Message-ID: <20260819060236.24665-4-xuanqiang.luo@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819060236.24665-1-xuanqiang.luo@linux.dev> References: <20260819060236.24665-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 PHY_READY before calling of_phy_leds(). If LED setup fails, the error path releases the initialized resources while the PHY state remains READY even though probing failed. Set PHY_READY only after LED setup succeeds. Fixes: 01e5b728e9e4 ("net: phy: Add a binding for PHY LEDs") Signed-off-by: Xuanqiang Luo Reviewed-by: Andrew Lunn --- drivers/net/phy/phy_device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 538e9ca44d093..8fd6fbf378f0a 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3799,9 +3799,6 @@ static int phy_probe(struct device *dev) phydev->supported); } =20 - /* Set the state to READY by default */ - phydev->state =3D PHY_READY; - /* Register the PHY LED triggers */ if (!phydev->is_on_sfp_module) phy_led_triggers_register(phydev); @@ -3815,6 +3812,9 @@ static int phy_probe(struct device *dev) goto out_unreg_led_triggers; } =20 + /* Set the state to READY by default */ + phydev->state =3D PHY_READY; + return 0; =20 out_unreg_led_triggers: --=20 2.43.0 From nobody Mon Sep 28 18:33:29 2026 Received: from mta0.migadu.com (out-151.mta0.migadu.com [91.218.175.151]) (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 BE0FE3CB8FC for ; Wed, 19 Aug 2026 06:03:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787119400; cv=none; b=s5gplKyOxJpzMvAd/NF/HN0hMP69bavU+ruh9WTgvnHunJah2sHDRq8vtrr2lcbdaowf05Lj4ezMpZjAlcOqiEmiO6Zs8KkaTUKzsS47U40oVk49ByzKlqlUIbHjsnyEyeilczUeDlvGLNph7Z2Hd/Yr67rw3D84Ue59lwVWXAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787119400; c=relaxed/simple; bh=8U0HypTh2AmuAZYNlvE7/CoEHCSH4bhE6LIbKUpdVg8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f7x/xh4H9xH1uVtjO38WwhQXTzdoMrdzaMRcxTKHdRsl6WXx7q8IvmXfH+on35606ILQFNfS2U5FgadXfvfcOrDNOUwo4NRycQMRJTynSkLKhAJd9Uz0n7Tjr90w9M3RKlUmysPh3VREBctFyS+xuZs1jVEJGEejrHjpPJJJEkI= 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=Nxl9E3Lc; arc=none smtp.client-ip=91.218.175.151 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="Nxl9E3Lc" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=8U0HypTh2AmuAZYNlvE7/CoEHCSH4bhE6LIbKUpdVg8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787119396; v=1; x=1787724196; b=Nxl9E3LcB83clKNHSslcYZvvRoOFACAOLnQxp2mcysM6La/03qo2z4mMt0rK7/pGS+kVkDMM nBpxWzx9HJng2tPydWqCnP38KY++CHAU3wMHkMh872d7yOQFlkZ7CcHtw87JbbwRTgvNluGbObN qPNdLeNlW7s6cVanJPNt52TU= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost.localdomain (116.128.244.171) by smtp.migadu.com with ESMTPS id 46c0bf875309408c; Wed, 19 Aug 2026 06:03:16 +0000 X-Migadu-Flow: FLOW_OUT From: Xuanqiang Luo To: netdev@vger.kernel.org, kuba@kernel.org, andrew@lunn.ch, maxime.chevallier@bootlin.com Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, chleroy@kernel.org, linux-kernel@vger.kernel.org, Xuanqiang Luo Subject: [PATCH net v3 4/5] net: phy: call driver remove when core initialization fails Date: Wed, 19 Aug 2026 14:02:35 +0800 Message-ID: <20260819060236.24665-5-xuanqiang.luo@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819060236.24665-1-xuanqiang.luo@linux.dev> References: <20260819060236.24665-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 Reviewed-by: Andrew Lunn --- 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 8fd6fbf378f0a..77318659ff985 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 @@ -3825,6 +3825,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 Mon Sep 28 18:33:29 2026 Received: from mta1.migadu.com (out-166.mta1.migadu.com [95.215.58.166]) (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 480C73CB546 for ; Wed, 19 Aug 2026 06:03:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.166 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787119409; cv=none; b=i6uhFEqdmyw7W0eRKxw3QxLjCwmEWD+jelV+h2p1HlFJb0lEPPdtEHhLwSSIK/0ttpAiHi0nyeWITVZHKOMKevQgi0wN/M0CMjEMLv8FmspjOp/vgEOYg/xVJ5dToQ6AWkcgV8AUOoyDWRYPfBHyM6zzGOH4ePbYakNqmPIb49s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787119409; c=relaxed/simple; bh=EmhKUTWRS2gxMw60Au+ba04qxs4iAzdtgW66bOcnh+w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MGp36DeMMATNhEbo6ltYwRvftdqme8rrtp/LlWS9iuwbBTdvOAySa2KNwdLT8BSgTLYaZz00e58yt6CdTLstQEUcwvL6XdRLaFADfNOlt3qldd5TXpo9+K2QCdu0Hytfdrx2aZZH9l/g95HEu7YgW1jozbXYkxoAAyWD+Y9HuK4= 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=wLO6x7Vc; arc=none smtp.client-ip=95.215.58.166 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="wLO6x7Vc" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=EmhKUTWRS2gxMw60Au+ba04qxs4iAzdtgW66bOcnh+w=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787119405; v=1; x=1787724205; b=wLO6x7Vcf/O9jrCnEos0tuFWv+JQlMOwc9BmDvJf91HGpgGZo4H6S07UjaG6BRcqbpEAoI+u UPY+2manfzwUEi0tZGvW6CiPbG5OrTTvHw8hiXFx092IkR1l5q1kyhcDnWthdUIPXIu0a2GdJgA m32s+pKoUaGGL366py48x8G0= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost.localdomain (116.128.244.171) by smtp.migadu.com with ESMTPS id 71db182c2f37b3bf; Wed, 19 Aug 2026 06:03:25 +0000 X-Migadu-Flow: FLOW_OUT From: Xuanqiang Luo To: netdev@vger.kernel.org, kuba@kernel.org, andrew@lunn.ch, maxime.chevallier@bootlin.com Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, chleroy@kernel.org, linux-kernel@vger.kernel.org, Xuanqiang Luo Subject: [PATCH net v3 5/5] net: phy: propagate errors from default port setup Date: Wed, 19 Aug 2026 14:02:36 +0800 Message-ID: <20260819060236.24665-6-xuanqiang.luo@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819060236.24665-1-xuanqiang.luo@linux.dev> References: <20260819060236.24665-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 Reviewed-by: Maxime Chevallier 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