netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Ratheesh Kannoth <rkannoth@marvell.com>,
	Russell King - ARM Linux <linux@armlinux.org.uk>,
	Andrew Lunn <andrew@lunn.ch>
Cc: David Miller <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org
Subject: Re: [PATCH] net: phy: simplify a check in phy_check_link_status
Date: Fri, 8 Mar 2024 08:09:42 +0100	[thread overview]
Message-ID: <793cc4d3-aaa8-4027-8212-9a090a44c2e4@gmail.com> (raw)
In-Reply-To: <20240308045058.1221154-1-rkannoth@marvell.com>

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


  reply	other threads:[~2024-03-08  7:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=793cc4d3-aaa8-4027-8212-9a090a44c2e4@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rkannoth@marvell.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;
as well as URLs for NNTP newsgroup(s).