All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v23 03/15] net: phylink: introduce internal phylink PCS handling
Date: Mon, 30 Nov 2026 23:25:48 +0000	[thread overview]
Message-ID: <sashiko-outbox-242227@kernel.org> (raw)
In-Reply-To: <20261129230558.612526-4-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] net: phylink: unmasked pcs_interfaces in
  phylink_parse_supported_interfaces()
- [Medium] net: phylink: missing error return in
  phylink_validate_mac_and_pcs()
- [Low] net: phylink: duplicated PCS lookup logic across three functions
--

commit c48ba0ce83717f538fa9d39f574827e8fe636c78
Author: Christian Marangi <ansuelsmth@gmail.com>

net: phylink: introduce internal phylink PCS handling

This commit introduces an internal PCS list in phylink as an alternative to
.mac_select_pcs, selecting a PCS based on config->pcs_interfaces and each
PCS's supported_interfaces bitmap.

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 20759fe47eaa7..35e82cccd39a2 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -536,6 +559,21 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl,
>  		pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface);
>  		if (IS_ERR(pcs))
>  			return PTR_ERR(pcs);
> +	/*
> +	 * Find a PCS in available PCS list for the requested interface.
> +	 *
> +	 * Skip searching if the MAC doesn't require a dedicated PCS for
> +	 * the requested interface.
> +	 */
> +	} else if (test_bit(state->interface, pl->config->pcs_interfaces)) {
> +		struct phylink_pcs *tmp;
> +
> +		list_for_each_entry(tmp, &pl->pcs_list, list) {
> +			if (!phylink_validate_pcs_interface(tmp, state->interface)) {
> +				pcs = tmp;
> +				break;
> +			}
> +		}
>  	}
>  
>  	if (pcs) {

[Severity: Medium]
Should phylink_validate_mac_and_pcs() return -EINVAL when state->interface is
set in pl->config->pcs_interfaces and no matching PCS is found in
pl->pcs_list?

When pcs remains NULL, phylink_validate_mac_and_pcs() skips PCS validation
and validates state->interface against MAC capabilities alone, allowing a
PCS-dependent mode without an available PCS to pass validation and later fail
in phylink_major_config().

[ ... ]
> @@ -969,12 +1004,22 @@ static void phylink_pcs_enable_eee(struct phylink_pcs *pcs)
>  static unsigned int phylink_inband_caps(struct phylink *pl,
>  					 phy_interface_t interface)
>  {
> -	struct phylink_pcs *pcs;
> +	struct phylink_pcs *pcs = NULL;
>  
> -	if (!pl->mac_ops->mac_select_pcs)
> -		return 0;
> +	if (pl->mac_ops->mac_select_pcs) {
> +		pcs = pl->mac_ops->mac_select_pcs(pl->config,
> +						  interface);
> +	} else if (test_bit(interface, pl->config->pcs_interfaces)) {
> +		struct phylink_pcs *tmp;
> +
> +		list_for_each_entry(tmp, &pl->pcs_list, list) {
> +			if (!phylink_validate_pcs_interface(tmp, interface)) {
> +				pcs = tmp;
> +				break;
> +			}
> +		}
> +	}
>  
> -	pcs = pl->mac_ops->mac_select_pcs(pl->config, interface);
>  	if (IS_ERR_OR_NULL(pcs))
>  		return 0;
>  
> @@ -1271,10 +1316,37 @@ static void phylink_major_config(struct phylink *pl, bool restart,
>  			pl->major_config_failed = true;
>  			return;
>  		}
> +	/*
> +	 * Find a PCS in available PCS list for the requested interface.
> +	 * This doesn't overwrite the previous .mac_select_pcs as either
> +	 * .mac_select_pcs or PCS list implementation are permitted.
> +	 *
> +	 * Skip searching if the MAC doesn't require a dedicated PCS for
> +	 * the requested interface.
> +	 */
> +	} else if (test_bit(state->interface, pl->config->pcs_interfaces)) {
> +		struct phylink_pcs *tmp;
> +
> +		list_for_each_entry(tmp, &pl->pcs_list, list) {
> +			if (!phylink_validate_pcs_interface(tmp,
> +							    state->interface)) {
> +				pcs = tmp;
> +				break;
> +			}
> +		}
> +
> +		if (!pcs) {
> +			phylink_err(pl,
> +				    "couldn't find a PCS for %s\n",
> +				    phy_modes(state->interface));
>  
> -		pcs_changed = pl->pcs != pcs;
> +			pl->major_config_failed = true;
> +			return;
> +		}
>  	}

[Severity: Low]
This isn't a bug, but the PCS lookup loop across pl->pcs_list (and the
mac_select_pcs vs. pcs_interfaces dispatch) is duplicated across
phylink_validate_mac_and_pcs(), phylink_inband_caps(), and
phylink_major_config().  Factoring this lookup into a helper would avoid the
duplication and keep the missing-PCS error handling consistent.

[ ... ]
> @@ -2042,6 +2168,62 @@ void phylink_update_mac_pause_capabilities(struct phylink *pl, unsigned long mac
>  }
>  EXPORT_SYMBOL_GPL(phylink_update_mac_pause_capabilities);
>  
> +static void phylink_parse_supported_interfaces(struct phylink *pl)
> +{
> +	struct phylink_pcs *pcs;
> +
> +	phy_interface_copy(pl->supported_interfaces,
> +			   pl->config->supported_interfaces);
> +
> +	/*
> +	 * Only add PCS-supported modes that phylink will select a PCS for.
> +	 * Otherwise, phylink may accept a PCS-only mode and configure it without
> +	 * a PCS.
> +	 */
> +	list_for_each_entry(pcs, &pl->pcs_list, list) {
> +		DECLARE_PHY_INTERFACE_MASK(pcs_interfaces);
> +
> +		phy_interface_copy(pcs_interfaces, pl->config->pcs_interfaces);
> +
> +		if (!phy_interface_empty(pcs->supported_interfaces))
> +			phy_interface_and(pcs_interfaces, pcs_interfaces,
> +					  pcs->supported_interfaces);
> +
> +		phy_interface_or(pl->supported_interfaces,
> +				 pl->supported_interfaces,
> +				 pcs_interfaces);
> +	}
> +}

[Severity: Medium]
Does phylink_parse_supported_interfaces() leave unavailable PCS modes set in
pl->supported_interfaces?

phylink_create() rejects an empty config->supported_interfaces before
phylink_fill_available_pcs() runs, so MAC drivers that require a PCS for some
or all modes populate those modes in config->supported_interfaces as well as
config->pcs_interfaces.  Because phylink_parse_supported_interfaces() copies
pl->config->supported_interfaces into pl->supported_interfaces without first
clearing pl->config->pcs_interfaces, any mode in config->pcs_interfaces that
is also in config->supported_interfaces remains enabled in
pl->supported_interfaces even when no attached PCS in pl->pcs_list supports
it.

Should pl->config->pcs_interfaces be masked out of pl->supported_interfaces
with phy_interface_andnot() before ORing in the interfaces supported by the
PCS instances in pl->pcs_list?

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

  reply	other threads:[~2026-11-30 23:25 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 23:05 [PATCH net-next v23 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 01/15] net: phylink: make PCS phylink instance access RCU protected Christian Marangi
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 02/15] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 03/15] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-11-30 23:25   ` sashiko-bot [this message]
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 04/15] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 05/15] net: phylink: make phylink_validate state locked Christian Marangi
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 06/15] net: phylink: add capabilities helpers and track modified advertising Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 07/15] net: sfp: support deferred module insertion Christian Marangi
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 08/15] net: phylink: support PCS provider release Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 09/15] net: phylink: support late PCS provider attach Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 10/15] net: Document PCS subsystem Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 11/15] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 12/15] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 14/15] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 15/15] net: airoha: add phylink support Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:48   ` netdev-bot+sashiko
2026-11-29 23:09 ` [PATCH net-next v23 00/15] net: pcs: Introduce support for fwnode PCS netdev-bot+sinfo

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=sashiko-outbox-242227@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.