All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH net-next v9 03/12] net: phylink: add phylink_release_pcs() to externally release a PCS
Date: Sat, 18 Jul 2026 09:01:14 +0000	[thread overview]
Message-ID: <20260718090114.81AB11F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260717065448.1498335-4-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Unconditional call to phylink_link_down() without updating old_link_state leads to multiple mac_link_down() calls and state machine desynchronization.
- [Medium] The phylink instance's supported ethtool link modes and advertising mask are not updated after a PCS is removed.
- [Medium] Polling timer is not stopped when the active polling PCS is released, causing a runaway timer.
- [Low] Reusing the function parameter 'pcs' as a loop iterator variable violates C scoping best practices and kernel coding standards.
--

--- Patch [3]: [PATCH net-next v9 03/12] net: phylink: add phylink_release_pcs() to externally release a PCS ---
commit 3d6c63e283b60421054ef189e8d1a2deb1f29536
Author: Christian Marangi <ansuelsmth@gmail.com>

net: phylink: add phylink_release_pcs() to externally release a PCS
    
Add phylink_release_pcs() to externally release a PCS from a phylink
instance. This can be used to handle case when a single PCS needs to be
removed and the phylink instance needs to be refreshed.

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index d96941d4c5235..986e0c1e3d678 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -917,6 +919,60 @@ static void phylink_resolve_an_pause(struct phylink_link_state *state)
[ ... ]
> +void phylink_release_pcs(struct phylink_pcs *pcs)
> +{
> +	struct phylink *pl;
> +
> +	ASSERT_RTNL();
> +
> +	pl = pcs->phylink;
> +	if (!pl)
> +		return;
> +
> +	mutex_lock(&pl->state_mutex);
> +
> +	list_del(&pcs->list);
> +	pcs->phylink = NULL;
> +
> +	/*
> +	 * Check if we are removing the PCS currently
> +	 * in use by phylink. If this is the case, tear down
> +	 * the link, force phylink resolve to reconfigure the
> +	 * interface mode, disable the current PCS and set the
> +	 * phylink PCS to NULL.
> +	 */
> +	if (pl->pcs == pcs) {
> +		phylink_link_down(pl);
> +		phylink_pcs_disable(pl->pcs);
> +
> +		pl->force_major_config = true;
> +		pl->pcs = NULL;
> +	}

[Severity: High]
Does calling phylink_link_down() here without also updating pl->old_link_state
cause state machine desynchronization?

If pl->old_link_state is true when the PCS is removed (such as for DSA switch
ports where there is no netdev), the link is logically brought down, but
pl->old_link_state remains true. This could cause subsequent link-up events to
be ignored because phylink thinks the link is already up, leaving the
interface permanently dead.

[Severity: Medium]
When the active PCS has polling enabled (pcs->poll is true), does clearing
pl->pcs and triggering a resolve leave a runaway timer?

If phylink_major_config() is called by the resolve task and no replacement PCS
is found, it may return early on error and bypass the phylink_pcs_poll_stop()
call. Could this cause the original timer to continue firing and re-arming
itself indefinitely?

> +
> +	mutex_unlock(&pl->state_mutex);
> +
> +	/* Refresh supported interfaces */
> +	phy_interface_copy(pl->supported_interfaces,
> +			   pl->config->supported_interfaces);
> +	list_for_each_entry(pcs, &pl->pcs_list, list)
> +		phy_interface_or(pl->supported_interfaces,
> +				 pl->supported_interfaces,
> +				 pcs->supported_interfaces);

[Severity: Low]
This isn't a bug, but does reusing the function parameter pcs as the list
iterator variable overwrite its pointer value?

When the loop terminates, pcs will point to an invalid structure offset
derived from the list head. Using a separate iterator variable would avoid
corrupting the parameter.

[Severity: Medium]
While pl->supported_interfaces is updated here, is it also necessary to
update the phylink instance's supported ethtool link modes and advertising
mask?

Without calling phylink_validate() or similar to update pl->supported and
pl->link_config.advertising, these masks might continue to advertise the
capabilities of the removed PCS. Could this lead to runtime connection
failures if userspace or the PHY attempts to negotiate these now-unsupported
modes?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260717065448.1498335-1-ansuelsmth@gmail.com?part=3

  reply	other threads:[~2026-07-18  9:01 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17  6:54 [PATCH net-next v9 00/12] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-07-17  6:54 ` [PATCH net-next v9 01/12] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 02/12] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 03/12] net: phylink: add phylink_release_pcs() to externally release a PCS Christian Marangi
2026-07-18  9:01   ` sashiko-bot [this message]
2026-07-17  6:54 ` [PATCH net-next v9 04/12] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 05/12] net: phylink: support late PCS provider attach Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 06/12] net: Document PCS subsystem Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 07/12] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-07-17  6:54 ` [PATCH net-next v9 08/12] of: property: fw_devlink: Add support for "pcs-handle" Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 09/12] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 10/12] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-07-17  6:54 ` [PATCH net-next v9 11/12] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-07-18  9:01   ` sashiko-bot
2026-07-17  6:54 ` [PATCH net-next v9 12/12] net: airoha: add phylink support Christian Marangi
2026-07-18  9:01   ` sashiko-bot

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=20260718090114.81AB11F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ansuelsmth@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.