[PATCH net v3] net: dsa: mt7530: fix impossible MDIO address and issue warning
Jakub Kicinski
kuba at kernel.org
Thu Jul 4 07:16:00 PDT 2024
On Thu, 4 Jul 2024 11:48:42 +0100 Daniel Golle wrote:
> > > +return ((((phy_addr - MT7530_NUM_PORTS) & ~MT7530_NUM_PORTS) % PHY_MAX_ADDR) +
> > > + MT7530_NUM_PORTS) & (PHY_MAX_ADDR - 1);
> >
> > nit: the return statement lacks indentation
>
> Yes, lacks an additional space to match the level of the first open parentheses.
> I'll fix that in the next round.
To be clear I meant the line with "return", not the continuation line
starting with MT7530_NUM_PORTS
> > but also based on the comment, isn't it:
> >
> > return (round_down(phy_addr, MT7530_NUM_PORTS + 1) - 1) & (PHY_MAX_ADDR - 1);
>
> The original, more complicated statement covers also the correct addresses,
> ie. 31 -> 31, 7 -> 7, 15 -> 15, 23 -> 23. However, the function is never
> called if the address is deemed correct, so that doesn't actually matter.
>
> It's kinda difficult to decide whether it is more important to return
> correct results also for values never used with the current code, or
> have a slightly more readable and shorter function but with expectations
> regarding the input values given by the caller.
>
> Opinions?
No strong opinion, but I do think "% PHY_MAX_ADDR" is superfluous, no?
The masking at the end with "& (PHY_MAX_ADDR - 1)" will take care of
truncation.
More information about the Linux-mediatek
mailing list