From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: Xuanqiang Luo <xuanqiang.luo@linux.dev>,
netdev@vger.kernel.org, andrew@lunn.ch, kuba@kernel.org
Cc: hkallweit1@gmail.com, chleroy@kernel.org,
qingfang.deng@siflower.com.cn, hao.guan@siflower.com.cn,
linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com,
pabeni@redhat.com, linux-kernel@vger.kernel.org,
Xuanqiang Luo <luoxuanqiang@kylinos.cn>
Subject: Re: [PATCH net v5 1/6] net: phy: split phy_probe() error paths
Date: Mon, 31 Aug 2026 09:58:00 +0200 [thread overview]
Message-ID: <9f6b5db7-b791-4a28-8ba8-fb2fd971ae7c@bootlin.com> (raw)
In-Reply-To: <20260823035600.188864-2-xuanqiang.luo@linux.dev>
Hi,
On 8/23/26 05:55, Xuanqiang Luo wrote:
> From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
>
> phy_probe() uses one cleanup path for failures at every initialization
> stage. This runs cleanup for resources that have not been initialized.
>
> After a successful probe and remove, phy_led_triggers_unregister() can
> leave phy_num_led_triggers non-zero after freeing the trigger array. If a
> subsequent probe fails before LED trigger registration, the common error
> path calls phy_led_triggers_unregister() with a NULL array and stale count,
> causing a NULL dereference.
>
> Split the cleanup by initialization stage so each failure path unwinds only
> the resources that may have been initialized. Unregister LED triggers
> before releasing the SFP upstream and ports, because the LED triggers are
> initialized after those resources and must be unwound first.
>
> Fixes: c8dbdc6e380e ("net: phy: register phy led_triggers during probe to avoid AB-BA deadlock")
> Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Maxime
> ---
> 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 94b2e85e00a37..2cf70471ae089 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -3706,7 +3706,7 @@ static int phy_probe(struct device *dev)
> if (phydev->drv->probe) {
> err = phydev->drv->probe(phydev);
> if (err)
> - goto out;
> + goto out_reset;
> }
>
> phy_disable_interrupts(phydev);
> @@ -3727,7 +3727,7 @@ static int phy_probe(struct device *dev)
> err = genphy_read_abilities(phydev);
>
> if (err)
> - goto out;
> + goto out_reset;
>
> if (!linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
> phydev->supported))
> @@ -3744,7 +3744,7 @@ static int phy_probe(struct device *dev)
>
> err = phy_setup_ports(phydev);
> if (err)
> - goto out;
> + goto out_sfp_release;
>
> phy_advertise_supported(phydev);
>
> @@ -3753,7 +3753,7 @@ static int phy_probe(struct device *dev)
> */
> err = genphy_c45_read_eee_adv(phydev, phydev->advertising_eee);
> if (err)
> - goto out;
> + goto out_sfp_release;
>
> /* Get the EEE modes we want to prohibit. */
> of_set_phy_eee_broken(phydev);
> @@ -3806,20 +3806,22 @@ static int phy_probe(struct device *dev)
> if (IS_ENABLED(CONFIG_PHYLIB_LEDS) && !phy_driver_is_genphy(phydev)) {
> err = of_phy_leds(phydev);
> if (err)
> - goto out;
> + goto out_unreg_led_triggers;
> }
>
> return 0;
>
> -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 = NULL;
>
> phy_cleanup_ports(phydev);
>
> - 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);
>
next prev parent reply other threads:[~2026-08-31 7:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-23 3:55 [PATCH net v5 0/6] net: phy: fix cleanup after probe failure Xuanqiang Luo
2026-08-23 3:55 ` [PATCH net v5 1/6] net: phy: split phy_probe() error paths Xuanqiang Luo
2026-08-31 7:58 ` Maxime Chevallier [this message]
2026-08-23 3:55 ` [PATCH net v5 2/6] net: phy: unregister SFP upstream before port cleanup Xuanqiang Luo
2026-08-31 7:58 ` Maxime Chevallier
2026-08-23 3:55 ` [PATCH net v5 3/6] net: phy: set PHY_READY after LED setup Xuanqiang Luo
2026-08-23 3:55 ` [PATCH net v5 4/6] net: phy: call driver remove when core initialization fails Xuanqiang Luo
2026-08-23 3:55 ` [PATCH net v5 5/6] net: phy: propagate errors from default port setup Xuanqiang Luo
2026-08-23 3:56 ` [PATCH net v5 6/6] net: phy: avoid double-free after LED trigger registration failure Xuanqiang Luo
2026-08-27 11:40 ` Paolo Abeni
2026-08-31 0:30 ` [PATCH net v5 0/6] net: phy: fix cleanup after probe failure patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9f6b5db7-b791-4a28-8ba8-fb2fd971ae7c@bootlin.com \
--to=maxime.chevallier@bootlin.com \
--cc=andrew@lunn.ch \
--cc=chleroy@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hao.guan@siflower.com.cn \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=luoxuanqiang@kylinos.cn \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=qingfang.deng@siflower.com.cn \
--cc=xuanqiang.luo@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox