lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZqgoLC77GeJ1yyYq@shell.armlinux.org.uk>
Date: Tue, 30 Jul 2024 00:39:24 +0100
From: "Russell King (Oracle)" <linux@...linux.org.uk>
To: Pawel Dembicki <paweldembicki@...il.com>
Cc: netdev@...r.kernel.org, Andrew Lunn <andrew@...n.ch>,
	Florian Fainelli <f.fainelli@...il.com>,
	Vladimir Oltean <olteanv@...il.com>,
	"David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
	Heiner Kallweit <hkallweit1@...il.com>,
	Linus Walleij <linus.walleij@...aro.org>,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next 9/9] net: phy: vitesse: implement downshift in
 vsc73xx phys

On Mon, Jul 29, 2024 at 11:06:15PM +0200, Pawel Dembicki wrote:
> +static int vsc73xx_get_downshift(struct phy_device *phydev, u8 *data)
> +{
> +	int page, val, cnt, enable;
> +
> +	page = phy_select_page(phydev, MII_VSC73XX_EXT_PAGE_1E);
> +	if (page < 0)
> +		return page;
> +
> +	val = __phy_read(phydev, MII_VSC73XX_PHY_CTRL_EXT3);
> +	if (val < 0)
> +		goto restore_page;
> +
> +	enable = FIELD_GET(MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_EN, val);
> +	cnt = FIELD_GET(MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_CNT, val) + 2;
> +
> +	*data = enable ? cnt : DOWNSHIFT_DEV_DISABLE;
> +
> +restore_page:
> +	phy_restore_page(phydev, page, val);
> +	return 0;

If you're going to use phy_select_page()..phy_restore_page(), please
read the documentation. If the __phy_read() fails, then you're
returning zero from this function, but leaving *data uninitialised.
Surely not what you want.

In any case, this complexity is unnecessary.

static int vsc73xx_get_downshift(struct phy_device *phydev, u8 *data)
{
	int val, enable, cnt;

	val = phy_read_paged(phydev, MII_VSC73XX_EXT_PAGE_1E,
			     MII_VSC73XX_PHY_CTRL_EXT3);
	if (val < 0)
		return val;

	enable = FIELD_GET(MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_EN, val);
	cnt = FIELD_GET(MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_CNT, val) + 2;

	*data = enable ? cnt : DOWNSHIFT_DEV_DISABLE;

	return 0;
}

is all that it needs.

> +}
> +
> +static int vsc73xx_set_downshift(struct phy_device *phydev, u8 cnt)
> +{
> +	int page, ret, val;
> +
> +	if (cnt > MII_VSC73XX_DOWNSHIFT_MAX)
> +		return -E2BIG;
> +	else if (cnt == MII_VSC73XX_DOWNSHIFT_INVAL)
> +		return -EINVAL;
> +
> +	page = phy_select_page(phydev, MII_VSC73XX_EXT_PAGE_1E);
> +	if (page < 0)
> +		return page;
> +
> +	if (!cnt) {
> +		ret = __phy_clear_bits(phydev, MII_VSC73XX_PHY_CTRL_EXT3,
> +				       MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_EN);
> +	} else {
> +		val = MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_EN |
> +		      FIELD_PREP(MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_CNT,
> +				 cnt - 2);
> +
> +		ret = __phy_modify(phydev, MII_VSC73XX_PHY_CTRL_EXT3,
> +				   MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_EN |
> +				   MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_CNT,
> +				   val);
> +	}
> +
> +	ret = phy_restore_page(phydev, page, ret);
> +	if (ret < 0)
> +		return ret;

This is also needlessly over-complex.

	u16 mask, val;

	...

	mask = MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_EN;

	if (!cnt) {
		val = 0;
	} else {
		mask |= MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_CNT;
		val = MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_EN |
		      FIELD_PREP(MII_VSC73XX_PHY_CTRL_EXT3_DOWNSHIFT_CNT,
				 cnt - 2);
	}

	ret = phy_modify_paged(phydev, MII_VSC73XX_EXT_PAGE_1E,
			       MII_VSC73XX_PHY_CTRL_EXT3, mask, val);
	if (ret < 0)
		return ret;

Would be equivalent to your code above, only simpler.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ