Re: [net-next PATCH v7 2/4] net: phy: extend PHY package API to support multiple global address

From: Russell King (Oracle)
Date: Thu Dec 14 2023 - 18:54:50 EST


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:

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.

Honestly, I have wondered why the mdio bus address is a signed int, but
never decided to do anything about it.

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