Re: [RFC PATCH net-next v4 10/28] net: dsa: qca8k: handle error with qca8k_rmw operation

From: Andrew Lunn
Date: Sat May 08 2021 - 13:59:41 EST


> -static void
> +static int
> qca8k_reg_set(struct qca8k_priv *priv, u32 reg, u32 val)
> {
> - qca8k_rmw(priv, reg, 0, val);
> + int ret;
> +
> + ret = qca8k_rmw(priv, reg, 0, val);
> + if (ret < 0)
> + return ret;
> +
> + return 0;

This is wrong. Look at qca8k_rmw():

static u32
qca8k_rmw(struct qca8k_priv *priv, u32 reg, u32 mask, u32 val)
{
u16 r1, r2, page;
u32 ret;

qca8k_split_addr(reg, &r1, &r2, &page);

mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);

qca8k_set_page(priv->bus, page);
ret = qca8k_mii_read32(priv->bus, 0x10 | r2, r1);
ret &= ~mask;
ret |= val;
qca8k_mii_write32(priv->bus, 0x10 | r2, r1, ret);

mutex_unlock(&priv->bus->mdio_lock);

return ret;
}

First off, it returns a u32. So you cannot actually represent negative
error numbers.

Also, since it is returning what is now contained in the register,
that value might actually look like an error code.

I had a quick look at all the places qca8k_rmw() is called. As far as
i could see, the return value is never used. I suggest you double
check that, and then change this function. Make it return a negative
error code, or 0 on success. You can then simplify the code using the
return value.

Andrew