From: Larysa Zaremba <larysa.zaremba@intel.com>
To: Maxime Chevallier <maxime.chevallier@bootlin.com>
Cc: <davem@davemloft.net>, Andrew Lunn <andrew@lunn.ch>,
Jakub Kicinski <kuba@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <thomas.petazzoni@bootlin.com>,
Simon Horman <horms@kernel.org>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
Christophe Leroy <christophe.leroy@csgroup.eu>,
Herve Codina <herve.codina@bootlin.com>,
Romain Gantois <romain.gantois@bootlin.com>,
Jijie Shao <shaojijie@huawei.com>
Subject: Re: [PATCH net] net: phy: phy_caps: Don't skip better duplex macth on non-exact match
Date: Tue, 3 Jun 2025 15:10:44 +0200 [thread overview]
Message-ID: <aD70VBO4EZEUgLOW@soc-5CG4396X81.clients.intel.com> (raw)
In-Reply-To: <20250603083541.248315-1-maxime.chevallier@bootlin.com>
On Tue, Jun 03, 2025 at 10:35:40AM +0200, Maxime Chevallier wrote:
> When performing a non-exact phy_caps lookup, we are looking for a
> supported mode that matches as closely as possible the passed speed/duplex.
>
> Blamed patch broke that logic by returning a match too early in case
> the caller asks for half-duplex, as a full-duplex linkmode may match
> first, and returned as a non-exact match without even trying to mach on
> half-duplex modes.
>
> Reported-by: Jijie Shao <shaojijie@huawei.com>
> Closes: https://lore.kernel.org/netdev/20250603102500.4ec743cf@fedora/T/#m22ed60ca635c67dc7d9cbb47e8995b2beb5c1576
> Fixes: fc81e257d19f ("net: phy: phy_caps: Allow looking-up link caps based on speed and duplex")
> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Reviewed-by: Larysa Zaremba <larysa.zaremba@intel.com>
> ---
> drivers/net/phy/phy_caps.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/phy/phy_caps.c b/drivers/net/phy/phy_caps.c
> index 703321689726..d80f6a37edf1 100644
> --- a/drivers/net/phy/phy_caps.c
> +++ b/drivers/net/phy/phy_caps.c
> @@ -195,7 +195,7 @@ const struct link_capabilities *
> phy_caps_lookup(int speed, unsigned int duplex, const unsigned long *supported,
> bool exact)
> {
> - const struct link_capabilities *lcap, *last = NULL;
> + const struct link_capabilities *lcap, *match = NULL, *last = NULL;
>
> for_each_link_caps_desc_speed(lcap) {
> if (linkmode_intersects(lcap->linkmodes, supported)) {
> @@ -204,16 +204,19 @@ phy_caps_lookup(int speed, unsigned int duplex, const unsigned long *supported,
> if (lcap->speed == speed && lcap->duplex == duplex) {
> return lcap;
> } else if (!exact) {
> - if (lcap->speed <= speed)
> - return lcap;
> + if (!match && lcap->speed <= speed)
> + match = lcap;
> +
> + if (lcap->speed < speed)
> + break;
> }
> }
> }
>
> - if (!exact)
> - return last;
> + if (!match && !exact)
> + match = last;
>
> - return NULL;
> + return match;
> }
> EXPORT_SYMBOL_GPL(phy_caps_lookup);
>
> --
> 2.49.0
>
>
next prev parent reply other threads:[~2025-06-03 13:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-03 8:35 Maxime Chevallier
2025-06-03 9:43 ` Jijie Shao
2025-06-03 13:10 ` Larysa Zaremba [this message]
2025-06-05 10:24 ` Paolo Abeni
2025-06-06 8:19 ` Maxime Chevallier
2025-06-06 8:30 ` Russell King (Oracle)
2025-06-06 9:24 ` Maxime Chevallier
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=aD70VBO4EZEUgLOW@soc-5CG4396X81.clients.intel.com \
--to=larysa.zaremba@intel.com \
--cc=andrew@lunn.ch \
--cc=christophe.leroy@csgroup.eu \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=herve.codina@bootlin.com \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=romain.gantois@bootlin.com \
--cc=shaojijie@huawei.com \
--cc=thomas.petazzoni@bootlin.com \
/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
all inboxes | Powered by JetHome®