RE: [PATCH net-next] net: stmmac: Fix sparse warning

From: Jose Abreu
Date: Mon Oct 07 2019 - 11:22:57 EST


From: David Miller <davem@xxxxxxxxxxxxx>
Date: Oct/07/2019, 15:14:26 (UTC+00:00)

> From: Jose Abreu <Jose.Abreu@xxxxxxxxxxxx>
> Date: Mon, 7 Oct 2019 15:16:08 +0200
>
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > index 8b76745a7ec4..40b0756f3a14 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > @@ -4207,6 +4207,7 @@ static u32 stmmac_vid_crc32_le(__le16 vid_le)
> > static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_double)
> > {
> > u32 crc, hash = 0;
> > + __le16 pmatch = 0;
> > int count = 0;
> > u16 vid = 0;
> >
> > @@ -4221,11 +4222,11 @@ static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_double)
> > if (count > 2) /* VID = 0 always passes filter */
> > return -EOPNOTSUPP;
> >
> > - vid = cpu_to_le16(vid);
> > + pmatch = cpu_to_le16(vid);
> > hash = 0;
> > }
> >
> > - return stmmac_update_vlan_hash(priv, priv->hw, hash, vid, is_double);
> > + return stmmac_update_vlan_hash(priv, priv->hw, hash, pmatch, is_double);
> > }
>
> I dunno about this.
>
> The original code would use the last "vid" iterated over in the
> for_each_set_bit() loop if the priv->dma_cap.vlhash test does not
> pass.
>
> Now, it will use zero in that case.
>
> This does not look like an equivalent transformation.

It is intended behavior. HW specific callbacks:
dwmac4_update_vlan_hash() / dwxgmac2_update_vlan_hash(), will either use
Hash method or Perfect method so if priv->dma_cap.vlhash is not
available then pmatch will be last vid. Otherwise, it will be zero and
hash will be populated.

---
Thanks,
Jose Miguel Abreu