Message ID | 20210504222915.17206-4-ansuelsmth@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [RFC,net-next,v3,01/20] net: mdio: ipq8064: clean whitespaces in define | expand |
Context | Check | Description |
---|---|---|
netdev/apply | fail | Patch does not apply to net-next |
netdev/tree_selection | success | Clearly marked for net-next |
> +static int > qca8k_set_page(struct mii_bus *bus, u16 page) > { > if (page == qca8k_current_page) > - return; > + return 0; > > - if (bus->write(bus, 0x18, 0, page) < 0) > + if (bus->write(bus, 0x18, 0, page) < 0) { > dev_err_ratelimited(&bus->dev, > "failed to set qca8k page\n"); > + return -EBUSY; EBUSY is a bit odd. bus->write() should return an error code. Please return that. > @@ -161,14 +169,19 @@ static void > qca8k_write(struct qca8k_priv *priv, u32 reg, u32 val) > { > u16 r1, r2, page; > + int 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_set_page(priv->bus, page); > + if (ret < 0) > + goto exit; > + > qca8k_mii_write32(priv->bus, 0x10 | r2, r1, val); > > +exit: > mutex_unlock(&priv->bus->mdio_lock); Maybe make this function also return the error? > }
> > @@ -161,14 +169,19 @@ static void > > qca8k_write(struct qca8k_priv *priv, u32 reg, u32 val) > > { > > u16 r1, r2, page; > > + int 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_set_page(priv->bus, page); > > + if (ret < 0) > > + goto exit; > > + > > qca8k_mii_write32(priv->bus, 0x10 | r2, r1, val); > > > > +exit: > > mutex_unlock(&priv->bus->mdio_lock); > > Maybe make this function also return the error? Ah, sorry, a later patch does exactly that. Andrew
diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c index cdaf9f85a2cb..411b42d38819 100644 --- a/drivers/net/dsa/qca8k.c +++ b/drivers/net/dsa/qca8k.c @@ -127,16 +127,20 @@ qca8k_mii_write32(struct mii_bus *bus, int phy_id, u32 regnum, u32 val) "failed to write qca8k 32bit register\n"); } -static void +static int qca8k_set_page(struct mii_bus *bus, u16 page) { if (page == qca8k_current_page) - return; + return 0; - if (bus->write(bus, 0x18, 0, page) < 0) + if (bus->write(bus, 0x18, 0, page) < 0) { dev_err_ratelimited(&bus->dev, "failed to set qca8k page\n"); + return -EBUSY; + } + qca8k_current_page = page; + return 0; } static u32 @@ -149,9 +153,13 @@ qca8k_read(struct qca8k_priv *priv, u32 reg) mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED); - qca8k_set_page(priv->bus, page); + val = qca8k_set_page(priv->bus, page); + if (val < 0) + goto exit; + val = qca8k_mii_read32(priv->bus, 0x10 | r2, r1); +exit: mutex_unlock(&priv->bus->mdio_lock); return val; @@ -161,14 +169,19 @@ static void qca8k_write(struct qca8k_priv *priv, u32 reg, u32 val) { u16 r1, r2, page; + int 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_set_page(priv->bus, page); + if (ret < 0) + goto exit; + qca8k_mii_write32(priv->bus, 0x10 | r2, r1, val); +exit: mutex_unlock(&priv->bus->mdio_lock); } @@ -182,12 +195,16 @@ qca8k_rmw(struct qca8k_priv *priv, u32 reg, u32 mask, u32 val) mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED); - qca8k_set_page(priv->bus, page); + ret = qca8k_set_page(priv->bus, page); + if (ret < 0) + goto exit; + ret = qca8k_mii_read32(priv->bus, 0x10 | r2, r1); ret &= ~mask; ret |= val; qca8k_mii_write32(priv->bus, 0x10 | r2, r1, ret); +exit: mutex_unlock(&priv->bus->mdio_lock); return ret;
With a remote possibility, the set_page function can fail. Since this is a critical part of the write/read qca8k regs, propagate the error and terminate any read/write operation. Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com> --- drivers/net/dsa/qca8k.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-)