Re: [RFC PATCH net-next v3 07/20] net: dsa: qca8k: handle error with qca8k_rmw operation

From: Ansuel Smith
Date: Tue May 04 2021 - 20:51:46 EST


On Wed, May 05, 2021 at 02:46:23AM +0200, Andrew Lunn wrote:
> > -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;
>
> Maybe return qca8k_rmw(priv, reg, 0, val); ??
>
> > -static void
> > +static int
> > qca8k_reg_clear(struct qca8k_priv *priv, u32 reg, u32 val)
> > {
> > - qca8k_rmw(priv, reg, val, 0);
> > + int ret;
> > +
> > + ret = qca8k_rmw(priv, reg, val, 0);
> > + if (ret < 0)
> > + return ret;
> > +
> > + return 0;
> > }
>
> Maybe return qca8k_rmw(priv, reg, val, 0);
>
> > @@ -1249,17 +1280,20 @@ qca8k_port_bridge_join(struct dsa_switch *ds, int port, struct net_device *br)
> > /* Add this port to the portvlan mask of the other ports
> > * in the bridge
> > */
> > - qca8k_reg_set(priv,
> > - QCA8K_PORT_LOOKUP_CTRL(i),
> > - BIT(port));
> > + ret = qca8k_reg_set(priv,
> > + QCA8K_PORT_LOOKUP_CTRL(i),
> > + BIT(port));
> > + if (ret)
> > + return ret;
> > if (i != port)
> > port_mask |= BIT(i);
> > }
> > +
> > /* Add all other ports to this ports portvlan mask */
> > - qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
> > - QCA8K_PORT_LOOKUP_MEMBER, port_mask);
> > + ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
> > + QCA8K_PORT_LOOKUP_MEMBER, port_mask);
> >
> > - return 0;
> > + return ret < 0 ? ret : 0;
>
> Can this is simplified to
>
> return = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
> QCA8K_PORT_LOOKUP_MEMBER, port_mask);
>
> > @@ -1396,18 +1430,19 @@ qca8k_port_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
> > struct netlink_ext_ack *extack)
> > {
> > struct qca8k_priv *priv = ds->priv;
> > + int ret;
> >
> > if (vlan_filtering) {
> > - qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
> > - QCA8K_PORT_LOOKUP_VLAN_MODE,
> > - QCA8K_PORT_LOOKUP_VLAN_MODE_SECURE);
> > + ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
> > + QCA8K_PORT_LOOKUP_VLAN_MODE,
> > + QCA8K_PORT_LOOKUP_VLAN_MODE_SECURE);
> > } else {
> > - qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
> > - QCA8K_PORT_LOOKUP_VLAN_MODE,
> > - QCA8K_PORT_LOOKUP_VLAN_MODE_NONE);
> > + ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
> > + QCA8K_PORT_LOOKUP_VLAN_MODE,
> > + QCA8K_PORT_LOOKUP_VLAN_MODE_NONE);
> > }
> >
> > - return 0;
> > + return ret < 0 ? ret : 0;
>
> What does qca8k_rmw() actually return?
>
> Andrew

qca8k_rmw in the original code returns the value read from the reg and
modified. So this is why all the strange checks. The idea is to not
change the original return values of the users so I check if every return
value is negative and return 0 in all the other cases.