Commit 81fe9248 authored by Simon Horman's avatar Simon Horman Committed by ZhangPeng
Browse files

net: stmmac: Correct byte order of perfect_match

stable inclusion
from stable-v6.6.44
commit 4384135d22174c3e52a3947f3f1e520bfa82fe79
bugzilla: https://gitee.com/openeuler/kernel/issues/IAHMJO

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=4384135d22174c3e52a3947f3f1e520bfa82fe79



--------------------------------

[ Upstream commit e9dbebae2e3c338122716914fe105458f41e3a4a ]

The perfect_match parameter of the update_vlan_hash operation is __le16,
and is correctly converted from host byte-order in the lone caller,
stmmac_vlan_update().

However, the implementations of this caller, dwxgmac2_update_vlan_hash()
and dwxgmac2_update_vlan_hash(), both treat this parameter as host byte
order, using the following pattern:

	u32 value = ...
	...
	writel(value | perfect_match, ...);

This is not correct because both:
1) value is host byte order; and
2) writel expects a host byte order value as it's first argument

I believe that this will break on big endian systems. And I expect it
has gone unnoticed by only being exercised on little endian systems.

The approach taken by this patch is to update the callback, and it's
caller to simply use a host byte order value.

Flagged by Sparse.
Compile tested only.

Fixes: c7ab0b80 ("net: stmmac: Fallback to VLAN Perfect filtering if HASH is not available")
Signed-off-by: default avatarSimon Horman <horms@kernel.org>
Reviewed-by: default avatarMaxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarZhangPeng <zhangpeng362@huawei.com>
parent 9ad03c70
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -982,7 +982,7 @@ static void dwmac4_set_mac_loopback(void __iomem *ioaddr, bool enable)
}

static void dwmac4_update_vlan_hash(struct mac_device_info *hw, u32 hash,
				    __le16 perfect_match, bool is_double)
				    u16 perfect_match, bool is_double)
{
	void __iomem *ioaddr = hw->pcsr;
	u32 value;
+1 −1
Original line number Diff line number Diff line
@@ -615,7 +615,7 @@ static int dwxgmac2_rss_configure(struct mac_device_info *hw,
}

static void dwxgmac2_update_vlan_hash(struct mac_device_info *hw, u32 hash,
				      __le16 perfect_match, bool is_double)
				      u16 perfect_match, bool is_double)
{
	void __iomem *ioaddr = hw->pcsr;

+1 −1
Original line number Diff line number Diff line
@@ -385,7 +385,7 @@ struct stmmac_ops {
			     struct stmmac_rss *cfg, u32 num_rxq);
	/* VLAN */
	void (*update_vlan_hash)(struct mac_device_info *hw, u32 hash,
				 __le16 perfect_match, bool is_double);
				 u16 perfect_match, bool is_double);
	void (*enable_vlan)(struct mac_device_info *hw, u32 type);
	int (*add_hw_vlan_rx_fltr)(struct net_device *dev,
				   struct mac_device_info *hw,
+2 −2
Original line number Diff line number Diff line
@@ -6490,7 +6490,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;
	u16 pmatch = 0;
	int count = 0;
	u16 vid = 0;

@@ -6505,7 +6505,7 @@ static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_double)
		if (count > 2) /* VID = 0 always passes filter */
			return -EOPNOTSUPP;

		pmatch = cpu_to_le16(vid);
		pmatch = vid;
		hash = 0;
	}