netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: phy: simplify a check in phy_check_link_status
@ 2024-03-07 21:16 Heiner Kallweit
  2024-03-08  4:50 ` [PATCH] " Ratheesh Kannoth
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Heiner Kallweit @ 2024-03-07 21:16 UTC (permalink / raw)
  To: Russell King - ARM Linux, Andrew Lunn, Paolo Abeni, Eric Dumazet,
	David Miller, Jakub Kicinski
  Cc: netdev

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.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/phy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index c3a0a5ee5..c4236564c 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: phy: simplify a check in phy_check_link_status
  2024-03-07 21:16 [PATCH net-next] net: phy: simplify a check in phy_check_link_status Heiner Kallweit
@ 2024-03-08  4:50 ` Ratheesh Kannoth
  2024-03-08  7:09   ` Heiner Kallweit
  2024-03-08  7:39 ` [EXTERNAL] [PATCH net-next] " Suman Ghosh
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Ratheesh Kannoth @ 2024-03-08  4:50 UTC (permalink / raw)
  To: rkannoth, netdev, linux-kernel, Heiner Kallweit

On 2024-03-08 at 02:46:12, Heiner Kallweit (hkallweit1@gmail.com) 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.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/net/phy/phy.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index c3a0a5ee5..c4236564c 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -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.

> -		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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: phy: simplify a check in phy_check_link_status
  2024-03-08  4:50 ` [PATCH] " Ratheesh Kannoth
@ 2024-03-08  7:09   ` Heiner Kallweit
  0 siblings, 0 replies; 6+ messages in thread
From: Heiner Kallweit @ 2024-03-08  7:09 UTC (permalink / raw)
  To: Ratheesh Kannoth, Russell King - ARM Linux, Andrew Lunn
  Cc: David Miller, Jakub Kicinski, Paolo Abeni, netdev

On 08.03.2024 05:50, Ratheesh Kannoth wrote:
> On 2024-03-08 at 02:46:12, Heiner Kallweit (hkallweit1@gmail.com) 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.
>>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>>  drivers/net/phy/phy.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
>> index c3a0a5ee5..c4236564c 100644
>> --- a/drivers/net/phy/phy.c
>> +++ b/drivers/net/phy/phy.c
>> @@ -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).

>> -		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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [EXTERNAL] [PATCH net-next] net: phy: simplify a check in phy_check_link_status
  2024-03-07 21:16 [PATCH net-next] net: phy: simplify a check in phy_check_link_status Heiner Kallweit
  2024-03-08  4:50 ` [PATCH] " Ratheesh Kannoth
@ 2024-03-08  7:39 ` Suman Ghosh
  2024-03-11 20:44 ` Heiner Kallweit
  2024-03-11 21:10 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 6+ messages in thread
From: Suman Ghosh @ 2024-03-08  7:39 UTC (permalink / raw)
  To: Heiner Kallweit, Russell King - ARM Linux, Andrew Lunn,
	Paolo Abeni, Eric Dumazet, David Miller, Jakub Kicinski
  Cc: netdev

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

>-----Original Message-----
>From: Heiner Kallweit <hkallweit1@gmail.com>
>Sent: Friday, March 8, 2024 2:46 AM
>To: Russell King - ARM Linux <linux@armlinux.org.uk>; Andrew Lunn
><andrew@lunn.ch>; Paolo Abeni <pabeni@redhat.com>; Eric Dumazet
><edumazet@google.com>; David Miller <davem@davemloft.net>; Jakub
>Kicinski <kuba@kernel.org>
>Cc: netdev@vger.kernel.org
>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.
>
>Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>---
> drivers/net/phy/phy.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index
>c3a0a5ee5..c4236564c 100644
>--- a/drivers/net/phy/phy.c
>+++ b/drivers/net/phy/phy.c
>@@ -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
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: phy: simplify a check in phy_check_link_status
  2024-03-07 21:16 [PATCH net-next] net: phy: simplify a check in phy_check_link_status Heiner Kallweit
  2024-03-08  4:50 ` [PATCH] " Ratheesh Kannoth
  2024-03-08  7:39 ` [EXTERNAL] [PATCH net-next] " Suman Ghosh
@ 2024-03-11 20:44 ` Heiner Kallweit
  2024-03-11 21:10 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 6+ messages in thread
From: Heiner Kallweit @ 2024-03-11 20:44 UTC (permalink / raw)
  To: Paolo Abeni, Eric Dumazet, David Miller, Jakub Kicinski
  Cc: netdev, Russell King - ARM Linux, Andrew Lunn

On 07.03.2024 22:16, Heiner Kallweit 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.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/net/phy/phy.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index c3a0a5ee5..c4236564c 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -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) {

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/d6ee6353-5cb0-4751-9b69-255ab62e6b56@gmail.com/T/
Whatever is better for you: If it can still be applied, fine. Otherwise I'd resubmit
after the merge window.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: phy: simplify a check in phy_check_link_status
  2024-03-07 21:16 [PATCH net-next] net: phy: simplify a check in phy_check_link_status Heiner Kallweit
                   ` (2 preceding siblings ...)
  2024-03-11 20:44 ` Heiner Kallweit
@ 2024-03-11 21:10 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-03-11 21:10 UTC (permalink / raw)
  To: Heiner Kallweit; +Cc: linux, andrew, pabeni, edumazet, davem, kuba, netdev

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

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.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-03-11 21:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-07 21:16 [PATCH net-next] net: phy: simplify a check in phy_check_link_status Heiner Kallweit
2024-03-08  4:50 ` [PATCH] " Ratheesh Kannoth
2024-03-08  7:09   ` Heiner Kallweit
2024-03-08  7:39 ` [EXTERNAL] [PATCH net-next] " Suman Ghosh
2024-03-11 20:44 ` Heiner Kallweit
2024-03-11 21:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).