Re: [PATCH] net: phy: simplify a check in phy_check_link_status

From: Ratheesh Kannoth
Date: Thu Mar 07 2024 - 23:51:43 EST


On 2024-03-08 at 02:46:12, Heiner Kallweit (hkallweit1@xxxxxxxxx) 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@xxxxxxxxx>
> ---
> 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