Re: [net-next PATCH v6 1/3] net: phy: extend PHY package API to support multiple global address

From: Christian Marangi
Date: Wed Dec 13 2023 - 10:50:43 EST


On Wed, Dec 13, 2023 at 03:45:24PM +0000, Russell King (Oracle) wrote:
> On Wed, Dec 13, 2023 at 11:57:28AM +0100, Christian Marangi wrote:
> > -static inline int phy_package_read(struct phy_device *phydev, u32 regnum)
> > +static inline int phy_package_read(struct phy_device *phydev,
> > + unsigned int addr_offset, u32 regnum)
> > {
> > struct phy_package_shared *shared = phydev->shared;
> > + int addr = shared->base_addr + addr_offset;
> >
> > - if (!shared)
> > + if (addr >= PHY_MAX_ADDR)
> > return -EIO;
>
> If we're going to check the address, I think we should check it
> properly, which means also checking whether it's become negative.
>
> Alternatively, we could consider making "addr" and "base_addr"
> unsigned types, since they should never be negative. However,
> that probably should be done as a separate patch before this one.
>

Maybe I'm confused but isn't already like that?
On phy_package_join base_addr is already checked if it's negative (and
rejected)

addr_offset is unsigned so it can't be negative.

We can switch addr to unsigned just for the sake of it but if I'm not
wrong all the sanity check are already done.

--
Ansuel