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, robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH net-next v7 06/12] net: Document PCS subsystem
Date: Tue, 16 Jun 2026 14:32:22 +0000	[thread overview]
Message-ID: <20260616143222.8ABAB1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260615122950.22281-7-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Error paths in `phylink_create()` free the `phylink` struct without unregistering the PCS notifier.
- [High] The PCS notifier is registered before the `phylink` instance is fully initialized, allowing concurrent notifications to dereference a NULL pointer.
- [Medium] Always-false unsigned comparison in `fwnode_parse_pcsspec()` masks actual error returns.
- [Medium] `fwnode_phylink_pcs_parse()` fails completely if `num_pcs` exceeds the actual number of entries in the device tree.
--

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

net: Document PCS subsystem
    
Add extensive documentation of the new PCS subsystem and the fwnode
implementation with producer/consumer API.

> diff --git a/drivers/net/pcs/pcs.c b/drivers/net/pcs/pcs.c
> new file mode 100644
> index 0000000000000..713b2ec22c97e
> --- /dev/null
> +++ b/drivers/net/pcs/pcs.c
> @@ -0,0 +1,257 @@

[ ... ]

> +static int fwnode_parse_pcsspec(const struct fwnode_handle *fwnode,
> +				unsigned int index, const char *name,
> +				struct fwnode_reference_args *out_args)
> +{
> +	int ret;
> +
> +	if (!fwnode)
> +		return -EINVAL;
> +
> +	if (name) {
> +		index = fwnode_property_match_string(fwnode, "pcs-names",
> +						     name);
> +		if (index < 0)

[Severity: Medium]
Since index is declared as an unsigned int, will this check for < 0 always be
false, potentially masking error returns from fwnode_property_match_string()?

> +			return index;
> +	}
> +
> +	ret = fwnode_property_get_reference_args(fwnode, "pcs-handle",
> +						 "#pcs-cells",
> +						 -1, index, out_args);
> +	if (ret || (name && index < 0))
> +		return ret;
> +
> +	return 0;
> +}

[ ... ]

> +int fwnode_phylink_pcs_parse(struct fwnode_handle *fwnode,
> +			     struct phylink_pcs **available_pcs,
> +			     unsigned int num_pcs)
> +{
> +	unsigned int i, found = 0;
> +
> +	if (!available_pcs)
> +		return -EINVAL;
> +
> +	if (!fwnode_property_present(fwnode, "pcs-handle"))
> +		return -ENODEV;
> +
> +	for (i = 0; i < num_pcs; i++) {
> +		struct phylink_pcs *pcs;
> +
> +		pcs = fwnode_pcs_get(fwnode, i);
> +		if (IS_ERR(pcs)) {
> +			/*
> +			 * Ignore -ENODEV error for PCS that still
> +			 * needs to probe.
> +			 */
> +			if (PTR_ERR(pcs) == -ENODEV)
> +				continue;
> +
> +			return PTR_ERR(pcs);

[Severity: Medium]
If num_pcs exceeds the actual number of entries in the device tree array,
fwnode_pcs_get() will return -ENOENT for the out-of-bounds index.

Will returning the error here cause the entire function to abort instead of
breaking gracefully and returning the valid entries found so far?

> +		}
> +
> +		available_pcs[found] = pcs;
> +		found++;
> +	}
> +
> +	return found;
> +}
> +EXPORT_SYMBOL_GPL(fwnode_phylink_pcs_parse);

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 087ac63f9193d..0734c98498a99 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c

[ ... ]

> @@ -1867,6 +2093,33 @@ struct phylink *phylink_create(struct phylink_config *config,

[ ... ]

> +	/* Register notifier for late PCS attach */
> +	if (!phy_interface_empty(config->pcs_interfaces)) {
> +		pl->fwnode_pcs_nb.notifier_call = pcs_provider_notify;
> +		register_fwnode_pcs_notifier(&pl->fwnode_pcs_nb);
> +	}
>  
>  	pl->config = config;

[Severity: High]
If a PCS provider is registered concurrently right after the notifier is added,
pcs_provider_notify() could execute before pl->config is initialized here.

Will the callback attempt to dereference a NULL pl->config->dev and crash?

[Severity: High]
If an error occurs later in phylink_create() (for example, if
phylink_parse_mode(), phylink_parse_fixedlink(), or phylink_register_sfp()
fail), the function calls kfree(pl) and returns.

Does this error path leave the notifier registered to freed memory, leading
to a use-after-free regression when the next PCS provider is added?

>  	if (config->type == PHYLINK_NETDEV) {

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

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

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