]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: stmmac: Correct byte order of perfect_match
authorSimon Horman <horms@kernel.org>
Tue, 23 Jul 2024 13:29:27 +0000 (14:29 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 24 Jul 2024 14:11:44 +0000 (15:11 +0100)
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: c7ab0b8088d7 ("net: stmmac: Fallback to VLAN Perfect filtering if HASH is not available")
Signed-off-by: Simon Horman <horms@kernel.org>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
drivers/net/ethernet/stmicro/stmmac/hwif.h
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

index dbd9f93b2460f00ec62725044e00c3e279e91c63..f98741d2607ec45b6558d3da817c3e10792386c8 100644 (file)
@@ -977,7 +977,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;
index 6a987cf598e4fb7fdee9e42781220b15d72c8462..f196cd99d51049d609d0c8b6b7076bdceffffad0 100644 (file)
@@ -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;
 
index 97934ccba5b1abc98c591efb18252332ab15cb6e..e53c3236277498b8662b74073488bad8ff173853 100644 (file)
@@ -393,7 +393,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);
        void (*rx_hw_vlan)(struct mac_device_info *hw, struct dma_desc *rx_desc,
                           struct sk_buff *skb);
index 4b6a359e5a945934aab2379dd1a047426a47e86b..12689774d75585db08ba38495e98913f499136e1 100644 (file)
@@ -6641,7 +6641,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;
 
@@ -6656,7 +6656,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;
        }