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

Yury Norov yury.norov at gmail.com
Mon Sep 7 21:54:36 UTC 2026


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 at nvidia.com>
---
 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



More information about the Intel-wired-lan mailing list