Devicetree
 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 02/12] net: phylink: introduce internal phylink PCS handling
Date: Sat, 18 Jul 2026 09:01:15 +0000	[thread overview]
Message-ID: <20260718090116.1D1B61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260717065448.1498335-3-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] phylink_validate_mac_and_pcs() validates an interface as supported even when its required dedicated PCS is missing.
- [High] Missing list_del() in the unlink_pcs_list error path of phylink_create() leaves dangling list pointers in externally-owned PCS structures.
- [Medium] phylink_fill_available_pcs() uses list_add() instead of list_add_tail(), reversing the intended priority order of the provided PCS array.
--

--- Patch [2]: [PATCH net-next v9 02/12] net: phylink: introduce internal phylink PCS handling ---
commit 867ad4be39467be718a5df59cf2a9739b1c43531
Author: Christian Marangi <ansuelsmth@gmail.com>
Subject: net: phylink: introduce internal phylink PCS handling

Introduces an alternative to mac_select_pcs by shifting the PCS selection logic
entirely to phylink using the supported_interface value in the PCS struct.
A new pcs_list tracks available PCS instances.

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 3464e3ec56997..d96941d4c5235 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -530,9 +552,24 @@ 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);
> +
> +		pcs_found = !!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)) {
> +		list_for_each_entry(pcs, &pl->pcs_list, list) {
> +			if (!phylink_validate_pcs_interface(pcs, state->interface)) {
> +				pcs_found = true;
> +				break;
> +			}
> +		}
>  	}
>  
> -	if (pcs) {
> +	if (pcs_found) {

[Severity: High]
If the MAC requires a dedicated PCS (test_bit returns true) but no available PCS
supports the requested interface, pcs_found remains false. Does this wrongly
skip the PCS validation block and proceed to MAC capabilities validation without
returning an error?

If so, it seems like phylink_major_config() will later fail when it performs
this same lookup, resulting in a delayed setup failure. Should we return -EINVAL
here if pcs_found is false but a dedicated PCS is required?

[ ... ]
> +static int phylink_fill_available_pcs(struct phylink *pl,
> +				      struct phylink_config *config)
> +{
[ ... ]
> +	for (i = 0; i < config->num_possible_pcs; i++) {
> +		struct phylink_pcs *pcs = pcss[i];
> +
> +		if (!pcs)
> +			continue;
> +
> +		list_add(&pcs->list, &pl->pcs_list);
> +	}

[Severity: Medium]
Since list_add() inserts elements at the head of the list, does this reverse the
priority order of the pcss array provided by the MAC driver?

Because lookups return the first matching PCS in the list, would using
list_add_tail() be needed to ensure the highest-priority PCS from the array is
correctly chosen?

[ ... ]
> @@ -1854,13 +1964,17 @@ struct phylink *phylink_create(struct phylink_config *config,
[ ... ]
>  	return pl;
> +
> +unlink_pcs_list:
> +	list_for_each_entry(pcs, &pl->pcs_list, list)
> +		pcs->phylink = NULL;
> +free_pl:
> +	kfree(pl);
> +	return ERR_PTR(ret);
>  }
>  EXPORT_SYMBOL_GPL(phylink_create);

[Severity: High]
If phylink_create() encounters an error and takes the unlink_pcs_list path, does
omitting list_del(&pcs->list) leave dangling pointers in the externally-owned
phylink_pcs structures once the phylink instance is freed?

If a MAC driver defers probe or retries initialization, passing these same
structures back to phylink_create() could trigger list corruption or a
use-after-free since their list nodes would still point to the freed
pl->pcs_list.

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

  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 [this message]
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
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=20260718090116.1D1B61F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox