RE: [PATCH 7/9] net: phy: use linkmode operation return values in phy_device.c

From: Loktionov, Aleksandr

Date: Wed Sep 09 2026 - 04:12:03 EST




> -----Original Message-----
> From: Yury Norov <yury.norov@xxxxxxxxx>
> Sent: Monday, September 7, 2026 11:55 PM
> To: Andrew Lunn <andrew@xxxxxxx>; Heiner Kallweit
> <hkallweit1@xxxxxxxxx>; Russell King <linux@xxxxxxxxxxxxxxx>; Raju
> Rangoju <Raju.Rangoju@xxxxxxx>; Prashanth Kumar K R
> <PrashanthKumar.K.R@xxxxxxx>; Nguyen, Anthony L
> <anthony.l.nguyen@xxxxxxxxx>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@xxxxxxxxx>; Jian Shen <shenjian15@xxxxxxxxxx>;
> Jijie Shao <shaojijie@xxxxxxxxxx>; David S. Miller
> <davem@xxxxxxxxxxxxx>; Eric Dumazet <edumazet@xxxxxxxxxx>; Jakub
> Kicinski <kuba@xxxxxxxxxx>; Paolo Abeni <pabeni@xxxxxxxxxx>; linux-
> kernel@xxxxxxxxxxxxxxx; netdev@xxxxxxxxxxxxxxx; intel-wired-
> lan@xxxxxxxxxxxxxxxx; linux-usb@xxxxxxxxxxxxxxx
> Cc: Yury Norov <ynorov@xxxxxxxxxx>; Yury Norov <yury.norov@xxxxxxxxx>;
> Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>; Andrew Morton
> <akpm@xxxxxxxxxxxxxxxxxxxx>
> Subject: [PATCH 7/9] net: phy: use linkmode operation return values in
> phy_device.c
>
> Use the return value of linkmode_and() where the resulting mask was
> previously scanned for emptiness. In phy_probe(), combine the AND and
> AND-NOT operations and use the return value of linkmode_and_andnot().
>
> Signed-off-by: Yury Norov <ynorov@xxxxxxxxxx>
> ---
> drivers/net/phy/phy_device.c | 14 ++++++--------
> include/linux/linkmode.h | 9 +++++++++
> 2 files changed, 15 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/net/phy/phy_device.c
> b/drivers/net/phy/phy_device.c index 94b2e85e00a3..3430605695c5 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -1565,8 +1565,7 @@ static int phy_sfp_module_insert(void *upstream,
> const struct sfp_eeprom_id *id)
>
> caps = sfp_get_module_caps(phydev->sfp_bus);
>
> - linkmode_and(sfp_support, port->supported, caps->link_modes);
> - if (linkmode_empty(sfp_support)) {
> + if (!linkmode_and(sfp_support, port->supported, caps-
> >link_modes)) {
> dev_err(&phydev->mdio.dev, "incompatible SFP module
> inserted, no common linkmode\n");
> return -EINVAL;
> }
> @@ -3761,15 +3760,14 @@ static int phy_probe(struct device *dev)
> /* Some PHYs may advertise, by default, not support EEE modes.
> So,
> * we need to clean them. In addition remove all disabled EEE
> modes.
> */
> - linkmode_and(phydev->advertising_eee, phydev->supported_eee,
> - phydev->advertising_eee);
> - linkmode_andnot(phydev->advertising_eee, phydev-
> >advertising_eee,
> - phydev->eee_disabled_modes);
> -
> /* There is no "enabled" flag. If PHY is advertising, assume it
> is
> * kind of enabled.
> */
> - phydev->eee_cfg.eee_enabled = !linkmode_empty(phydev-
> >advertising_eee);
> + phydev->eee_cfg.eee_enabled =
> + linkmode_and_andnot(phydev->advertising_eee,
> + phydev->advertising_eee,
> + phydev->supported_eee,
> + phydev->eee_disabled_modes);
>
> /* Get master/slave strap overrides */
> of_set_phy_timing_role(phydev);
> diff --git a/include/linux/linkmode.h b/include/linux/linkmode.h index
> c08632c10c3d..49587a2e0f69 100644
> --- a/include/linux/linkmode.h
> +++ b/include/linux/linkmode.h
> @@ -26,6 +26,15 @@ static inline bool linkmode_and(unsigned long *dst,
> const unsigned long *a,
> return bitmap_and(dst, a, b, __ETHTOOL_LINK_MODE_MASK_NBITS);
> }
>
> +static inline bool linkmode_and_andnot(unsigned long *dst,
> + const unsigned long *a,
> + const unsigned long *b,
> + const unsigned long *c)
> +{
> + return bitmap_and_andnot(dst, a, b, c,
> + __ETHTOOL_LINK_MODE_MASK_NBITS);
> +}
> +
> static inline void linkmode_or(unsigned long *dst, const unsigned
> long *a,
> const unsigned long *b)
> {
> --
> 2.53.0

Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@xxxxxxxxx>