Skip to contentSkip to conversation

net: phy: simplify a check in phy_check_link_status

PATCH Applied Heiner Kallweit 4 participants 6 messages Mar 7, 2024 – Mar 11, 2024

Subsystems (3)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

PATCH 1/1 net: phy: simplify a check in phy_check_link_status

Handling case err == 0 in the other branch allows to simplify the code. In addition I assume in "err & phydev->eee_cfg.tx_lpi_enabled" it should have been a logical and operator. It works as expected also with the bitwise and, but using a bitwise and with a bool value looks ugly to me.

---
 drivers/net/phy/phy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/phy/phy.c +2 -2
index c3a0a5ee5..c4236564c 100644
@@ -985,10 +985,10 @@ static int phy_check_link_status(struct phy_device *phydev)
 		phydev->state = PHY_RUNNING;
 		err = genphy_c45_eee_is_active(phydev,
 					       NULL, NULL, NULL);
-		if (err < 0)
+		if (err <= 0)
 			phydev->enable_tx_lpi = false;
 		else
-			phydev->enable_tx_lpi = (err & phydev->eee_cfg.tx_lpi_enabled);
+			phydev->enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled;
 
 		phy_link_up(phydev);
 	} else if (!phydev->link && phydev->state != PHY_NOLINK) {
Signature · 1 line
2.44.0
#1 lore raw
Quoted 16 lines · Heiner Kallweit

Handling case err == 0 in the other branch allows to simplify the code. In addition I assume in "err & phydev->eee_cfg.tx_lpi_enabled" it should have been a logical and operator. It works as expected also with the bitwise and, but using a bitwise and with a bool value looks ugly to me.

---
 drivers/net/phy/phy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/phy/phy.c +0 -0
index c3a0a5ee5..c4236564c 100644

drivers/net/phy/phy.c static int phy_check_link_status(struct phy_device *phydev) · line 987

Quoted 3 lines
drivers/net/phy/phy.c +0 -0
@@ -985,10 +985,10 @@ static int phy_check_link_status(struct phy_device *phydev)
 		phydev->state = PHY_RUNNING;
 		err = genphy_c45_eee_is_active(phydev,
 					       NULL, NULL, NULL);

IMO, better to rename "err" to "ret", and do if (ret == true). OR,
we should fix syntax of genphy_c45_eee_is_active() to return bool (true/false) than doing this, because function name suggest so , xxx_is_active(). err == 0, norm is for success case.

Quoted 11 lines
drivers/net/phy/phy.c +2 -3
-		if (err < 0)
+		if (err <= 0)
 			phydev->enable_tx_lpi = false;
 		else
-			phydev->enable_tx_lpi = (err & phydev->eee_cfg.tx_lpi_enabled);
+			phydev->enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled;
 
 		phy_link_up(phydev);
 	} else if (!phydev->link && phydev->state != PHY_NOLINK) {
--

2.44.0

author maintainer
#2 lore raw
Quoted 12 lines · Ratheesh Kannoth
Quoted 11 lines · Heiner Kallweit

Handling case err == 0 in the other branch allows to simplify the code. In addition I assume in "err & phydev->eee_cfg.tx_lpi_enabled" it should have been a logical and operator. It works as expected also with the bitwise and, but using a bitwise and with a bool value looks ugly to me.

---
 drivers/net/phy/phy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines

drivers/net/phy/phy.c static int phy_check_link_status(struct phy_device *phydev) · line 987

Quoted 8 lines
drivers/net/phy/phy.c +0 -0
index c3a0a5ee5..c4236564c 100644
@@ -985,10 +985,10 @@ static int phy_check_link_status(struct phy_device *phydev)
 		phydev->state = PHY_RUNNING;
 		err = genphy_c45_eee_is_active(phydev,
 					       NULL, NULL, NULL);

IMO, better to rename "err" to "ret", and do if (ret == true). OR,
we should fix syntax of genphy_c45_eee_is_active() to return bool (true/false) than doing this, because function name suggest so , xxx_is_active(). err == 0, norm is for success case.

Return value of genphy_c45_eee_is_active() is tristate int:
<0: error
0: eee not active
1: eee active (implicit cast from bool to int)

This tristate behavior isn't unusual, you can find it with other phylib functions too, another example are several of the rpm functions. So both, 0 and 1, are success cases (from a technical perspective).

Quoted 11 lines
Quoted 11 lines
drivers/net/phy/phy.c +2 -3
-		if (err < 0)
+		if (err <= 0)
 			phydev->enable_tx_lpi = false;
 		else
-			phydev->enable_tx_lpi = (err & phydev->eee_cfg.tx_lpi_enabled);
+			phydev->enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled;
 
 		phy_link_up(phydev);
 	} else if (!phydev->link && phydev->state != PHY_NOLINK) {
--

2.44.0

#3 lore raw
In reply to Heiner Kallweit

Hi Heiner,

To me it looks like both patches,
r8169: switch to new function phy_support_eee and net: phy: simplify a check in phy_check_link_status is related and can be pushed as a series. This will make change more harmonic. Because, you are moving setting of enable_tx_lpi in one patch and removing from the other one.

Regards,
Suman

Quoted 44 lines

-----Original Message-----
From: Heiner Kallweit <[email protected]>
Sent: Friday, March 8, 2024 2:46 AM
To: Russell King - ARM Linux <[email protected]>; Andrew Lunn <[email protected]>; Paolo Abeni <[email protected]>; Eric Dumazet <[email protected]>; David Miller <[email protected]>; Jakub Kicinski <[email protected]>
Cc: [email protected]
Subject: [EXTERNAL] [PATCH net-next] net: phy: simplify a check in phy_check_link_status

Handling case err == 0 in the other branch allows to simplify the code. In addition I assume in "err & phydev->eee_cfg.tx_lpi_enabled" it should have been a logical and operator. It works as expected also with the bitwise and, but using a bitwise and with a bool value looks ugly to me.

---
drivers/net/phy/phy.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/phy/phy.c index renamed from drivers/net/phy/phy.c +0 -0

c3a0a5ee5..c4236564c 100644

drivers/net/phy/phy.c +2 -2
@@ -985,10 +985,10 @@ static int phy_check_link_status(struct phy_device
 *phydev)
 		phydev->state = PHY_RUNNING;
 		err = genphy_c45_eee_is_active(phydev,
 					       NULL, NULL, NULL);
-		if (err < 0)
+		if (err <= 0)
 			phydev->enable_tx_lpi = false;
 		else
-			phydev->enable_tx_lpi = (err & phydev-
 >eee_cfg.tx_lpi_enabled);
+			phydev->enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled;
 
		phy_link_up(phydev);
	} else if (!phydev->link && phydev->state != PHY_NOLINK) {

--
2.44.0

author maintainer
#4 lore raw
In reply to Heiner Kallweit
Quoted 18 lines · Heiner Kallweit

Handling case err == 0 in the other branch allows to simplify the code. In addition I assume in "err & phydev->eee_cfg.tx_lpi_enabled" it should have been a logical and operator. It works as expected also with the bitwise and, but using a bitwise and with a bool value looks ugly to me.

---
 drivers/net/phy/phy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/phy/phy.c +0 -0
index c3a0a5ee5..c4236564c 100644
@@ -985,10 +985,10 @@ static int phy_check_link_status(struct phy_device *phydev)
 		phydev->state = PHY_RUNNING;
 		err = genphy_c45_eee_is_active(phydev,

drivers/net/phy/phy.c static int phy_check_link_status(struct phy_device *phydev) · line 994

Quoted 10 lines
drivers/net/phy/phy.c +2 -2
 					       NULL, NULL, NULL);
-		if (err < 0)
+		if (err <= 0)
 			phydev->enable_tx_lpi = false;
 		else
-			phydev->enable_tx_lpi = (err & phydev->eee_cfg.tx_lpi_enabled);
+			phydev->enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled;
 
 		phy_link_up(phydev);
 	} else if (!phydev->link && phydev->state != PHY_NOLINK) {

This patch was set to "changes requested" in patchwork. The comment that this refers to (make two patches a series) isn't applicable and I answered to it here:
https://lore.kernel.org/netdev/[email protected]/T/
Whatever is better for you: If it can still be applied, fine. Otherwise I'd resubmit after the merge window.

#5 lore raw
In reply to Heiner Kallweit
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Thu, 7 Mar 2024 22:16:12 +0100 you wrote:

Handling case err == 0 in the other branch allows to simplify the code. In addition I assume in "err & phydev->eee_cfg.tx_lpi_enabled" it should have been a logical and operator. It works as expected also with the bitwise and, but using a bitwise and with a bool value looks ugly to me.

[...]

Here is the summary with links:
- [net-next] net: phy: simplify a check in phy_check_link_status

    https://git.kernel.org/netdev/net-next/c/c786459fc827

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html