Re: [net-next,v3,01/11] net: phy: phy_port: Correctly recompute the port's linkmodes

From: Simon Horman

Date: Tue Feb 03 2026 - 12:58:30 EST


This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.

For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net: phy: phy_port: Correctly recompute the port's linkmodes

This commit fixes phy_port_update_supported() to properly filter linkmodes
instead of incorrectly or'ing medium-specific modes to the existing support.
It moves the medium iteration inside a check for empty port->supported.

Fixes: 589e934d2735 ("net: phy: Introduce PHY ports representation")

> diff --git a/drivers/net/phy/phy_port.c b/drivers/net/phy/phy_port.c
> --- a/drivers/net/phy/phy_port.c
> +++ b/drivers/net/phy/phy_port.c

[ ... ]

> @@ -132,6 +126,19 @@ void phy_port_update_supported(struct phy_port *port)
> port->pairs = max_t(int, port->pairs,
> ethtool_linkmode_n_pairs(mode));
>
> + if (linkmode_empty(port->supported)) {
> + for_each_set_bit(i, &port->mediums,
> + __ETHTOOL_LINK_MEDIUM_LAST) {
> + __ETHTOOL_DECLARE_LINK_MODE_MASK(med_supported) = {0};
> +
> + phy_caps_medium_get_supported(med_supported, i,
> + port->pairs);
> + linkmode_or(supported, supported, med_supported);
> + }
> +
> + linkmode_and(port->supported, port->supported, supported);
> + }

Jakub Kicinski raised a concern in v2 about the AND operation when
port->supported starts empty. The v3 fix adds the
'if (linkmode_empty(port->supported))' check, but then still performs:

linkmode_and(port->supported, port->supported, supported);

inside that block. Since we just confirmed port->supported is empty,
ANDing it with anything will always produce an empty result.

Should this be linkmode_copy() or linkmode_or() instead of linkmode_and()
when port->supported starts empty?

Reference: https://lore.kernel.org/all/20260130040009.707764-1-kuba@xxxxxxxxxx/