All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH net-next v6 04/12] net: pcs: implement Firmware node support for PCS driver
Date: Wed, 10 Jun 2026 16:16:24 +0000	[thread overview]
Message-ID: <20260610161624.7008B1F00899@smtp.kernel.org> (raw)
In-Reply-To: <20260609151212.29469-5-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Unprotected list modification and iteration in phylink PCS list handling causes race conditions.
- [Medium] `fwnode_pcs_get_from_pcsspec()` incorrectly returns `-ENODEV` instead of `-EPROBE_DEFER` when a provider is not found.
- [Low] `fwnode_parse_pcsspec()` passes a negative error code as an unsigned index, masking the original error and causing out-of-bounds lookups.
--

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

net: pcs: implement Firmware node support for PCS driver

This commit implements the foundation for firmware node support in PCS drivers.
It introduces a simple provider API where a PCS driver can expose multiple PCS
instances with a get function. It also adds a generic parsing function for MAC
drivers to declare PCS in DT or ACPI.

> diff --git a/drivers/net/pcs/pcs.c b/drivers/net/pcs/pcs.c
> new file mode 100644
> index 0000000000000..72f56f55d198d
> --- /dev/null
> +++ b/drivers/net/pcs/pcs.c

[ ... ]

> +static int fwnode_parse_pcsspec(const struct fwnode_handle *fwnode, int index,
> +				const char *name,
> +				struct fwnode_reference_args *out_args)
> +{
> +	int ret;
> +
> +	if (!fwnode)
> +		return -ENOENT;
> +
> +	if (name)
> +		index = fwnode_property_match_string(fwnode, "pcs-names",
> +						     name);
> +
> +	ret = fwnode_property_get_reference_args(fwnode, "pcs-handle",
> +						 "#pcs-cells",
> +						 -1, index, out_args);

[Severity: Low]
If name is provided but fwnode_property_match_string() fails, it returns a
negative error code. Are we passing this negative value directly into
fwnode_property_get_reference_args(), which expects an unsigned int?

This could wrap around to a large positive integer, causing an out-of-bounds
fetch attempt that internally fails with -ENOENT. The original error code
would therefore be masked by -ENOENT.

Should this function check if (index < 0) return index; before proceeding?

> +	if (ret || (name && index < 0))
> +		return ret;
> +
> +	return 0;
> +}
> +
> +static struct phylink_pcs *
> +fwnode_pcs_get_from_pcsspec(struct fwnode_reference_args *pcsspec)
> +{
> +	struct fwnode_pcs_provider *provider;
> +	struct phylink_pcs *pcs = ERR_PTR(-ENODEV);

[Severity: Medium]
As stated in the kernel doc for fwnode_pcs_get(), it must return
-EPROBE_DEFER if the PCS is not present in the global providers list.
Is it intentional that fwnode_pcs_get_from_pcsspec() defaults to returning
-ENODEV here when a provider is not found?

This could break the standard kernel probe deferral mechanism for the consumer
driver, preventing it from deferring its probe to wait for the PCS driver to
load if fw_devlink is disabled or bypassed.

> +
> +	if (!pcsspec)
> +		return ERR_PTR(-EINVAL);
> +
> +	mutex_lock(&fwnode_pcs_mutex);
> +	list_for_each_entry(provider, &fwnode_pcs_providers, link) {
> +		if (provider->fwnode == pcsspec->fwnode) {
> +			pcs = provider->get(pcsspec, provider->data);
> +			if (!IS_ERR(pcs))
> +				break;
> +		}
> +	}
> +	mutex_unlock(&fwnode_pcs_mutex);
> +
> +	return pcs;
> +}

Regarding the integration of this feature with the phylink subsystem, is there a
risk of unprotected list modification and iteration causing a race condition?

[Severity: High]
The pl->pcs_list appears to be protected by mismatched locks. In
phylink_release_pcs() and pcs_provider_notify(), list modifications are
performed under rtnl_lock() but without holding pl->state_mutex:

drivers/net/phy/phylink.c:phylink_release_pcs() {
    ...
    list_del(&pcs->list);
    ...
}

Concurrently, the phylink_resolve() workqueue executes
phylink_major_config(), which iterates over pl->pcs_list using
list_for_each_entry() while holding pl->state_mutex but without holding
rtnl_lock():

drivers/net/phy/phylink.c:phylink_major_config() {
    ...
    list_for_each_entry(pcs, &pl->pcs_list, list) {
    ...
}

Since list modification and iteration are not synchronized by a common lock,
could this lead to linked-list corruption, torn reads, and use-after-free
crashes if the workqueue accesses a PCS that is being removed?

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

  reply	other threads:[~2026-06-10 16:16 UTC|newest]

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