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] [day] [month] [year] [list]
Date: Fri, 15 Dec 2023 09:16:27 +0000
From: "Russell King (Oracle)" <linux@...linux.org.uk>
To: Christian Marangi <ansuelsmth@...il.com>
Cc: Florian Fainelli <florian.fainelli@...adcom.com>,
	Broadcom internal kernel review list <bcm-kernel-feedback-list@...adcom.com>,
	Andrew Lunn <andrew@...n.ch>,
	Heiner Kallweit <hkallweit1@...il.com>,
	"David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
	Vladimir Oltean <olteanv@...il.com>,
	David Epping <david.epping@...singlinkelectronics.com>,
	Harini Katakam <harini.katakam@....com>, netdev@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [net-next PATCH v7 2/4] net: phy: extend PHY package API to
 support multiple global address

On Thu, Dec 14, 2023 at 06:29:28PM +0100, Christian Marangi wrote:
> On Thu, Dec 14, 2023 at 11:54:26PM +0000, Russell King (Oracle) wrote:
> > On Thu, Dec 14, 2023 at 05:54:51PM +0100, Christian Marangi wrote:
> > > What I don't like is the wrap check.
> > > 
> > > But I wonder... Isn't it easier to have 
> > > 
> > > unsigned int addr = shared->base_addr + addr_offset;
> > > 
> > > and check if >= PHY_MAC_ADDR?
> > > 
> > > Everything is unsigned (so no negative case) and wrap is not possible as
> > > nothing is downcasted.
> > 
> > I'm afraid that I LOL'd at "wrap is not possible" ! Of course it's
> > possible. Here's an example:
> >
> 
> Yes I just think about it and I'm also LOLing at the "not possible"...
> 
> > 	shared->base_addr is 20
> > 	addr_offset is ~0 (or -1 casted to an unsigned int)
> > 	addr becomes 19
> > 
> > How about:
> > 
> > 	if (addr_offset >= PHY_MAX_ADDR)
> > 		return -EIO;
> > 
> > 	addr = shared->base_addr + addr_offset;
> > 	if (addr >= PHY_MAX_ADDR)
> > 		return -EIO;
> > 
> > and then we could keep 'addr' as u8.
> 
> Ok just to make sure
> 
> static int phy_package_address(struct phy_device *phydev,
>                                unsigned int addr_offset)
> {
>         struct phy_package_shared *shared = phydev->shared;
>         unsigned int addr;
> 
>         if (addr_offset >= PHY_MAX_ADDR)
>                 return -EIO;
> 
>         addr = shared->base_addr + addr_offset;
>         if (addr >= PHY_ADDR_MAX)
>                 return -EIO;
> 
>         /* we know that addr will be in the range 0..31 and thus the
>          * implicit cast to a signed int is not a problem.
>          */
>         return addr;
> }

Yep.

> And call u8 addr = phy_package_address(phydev, addr_offset);

This has to be int to cater for -EIO

> Maybe one if can be skipped with the following fun thing?
> 
> static int phy_package_address(struct phy_device *phydev,
>                                unsigned int addr_offset)
> {
>         struct phy_package_shared *shared = phydev->shared;
>         u8 base_addr = shared->base_addr;
> 
>         if (addr_offset >= PHY_MAX_ADDR - base_addr)
>                 return -EIO;

That also works.
> 
>         /* we know that addr will be in the range 0..31 and thus the
>          * implicit cast to a signed int is not a problem.
>          */
>         return base_addr + addr_offset;
> }
> 
> (don't hate me it's late here and my brain is half working ahahha)
> 
> > 
> > Honestly, I have wondered why the mdio bus address is a signed int, but
> > never decided to do anything about it.
> > 
> 
> Maybe because direct usage of mdiobus_ is discouraged and phy_write will
> use an addr that is already validated.

It's discourged in PHY drivers where one has the phy_device.

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