Messages in this thread | | | Date | Wed, 29 Mar 2023 21:35:17 +0200 | From | Andrew Lunn <> | Subject | Re: [RFC PATCH net-next v3 03/15] net: dsa: mt7530: use regmap to access switch register space |
| |
On Wed, Mar 29, 2023 at 07:33:17PM +0100, Daniel Golle wrote: > On Wed, Mar 29, 2023 at 06:24:21PM +0200, Andrew Lunn wrote: > > Thanks for splitting this patchset up. This is much easier to review. > > > > > +static u32 > > > +mt7530_mii_read(struct mt7530_priv *priv, u32 reg) > > > +{ > > > + int ret; > > > + u32 val; > > > + > > > + ret = regmap_read(priv->regmap, reg, &val); > > > + if (ret) { > > > + dev_err(priv->dev, > > > + "failed to read mt7530 register\n"); > > > + return ret; > > > > This is a u32 function. ret should be negative on error, which is > > going to be turned positive in order to return a u32. So you probably > > want to make this an int function. > > This is a pre-existing flaw in the code. As we are accessing 32-bit > registers there has just never been any meaningful error handling.
O.K. At least i would not return the negative error code. Return 0, or 0xdeadbeef or something. And consider adding a WARN_ON_ONCE() so it is very loud when it goes wrong.
> I guess the correct solution would be to not use the return value only > to indicate success or error, and use an additional u32* parameter for > the read value.
Yes, that is what mv88e6xxx does.
> However, I was hestitating to convert all the calls (they are many) to > follow that improved paradigm.
Yes, leave that for another time.
Andrew
| |