net: dsa: qca8k: fix an endian bug in qca8k_get_ethtool_stats()
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 9 Jun 2021 09:52:12 +0000 (12:52 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 9 Jun 2021 21:10:38 +0000 (14:10 -0700)
The "hi" variable is a u64 but the qca8k_read() writes to the top 32
bits of it.  That will work on little endian systems but it's a bit
subtle.  It's cleaner to make declare "hi" as a u32.  We will still need
to cast it when we shift it later on in the function but that's fine.

Fixes: 7c9896e37807 ("net: dsa: qca8k: check return value of read functions correctly")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/qca8k.c

index 6fe963ba23e8e6c46ec82c19e1b17a2a9675874e..9df3514d1ff26eb493d1e7e644212a82aafa38eb 100644 (file)
@@ -1412,7 +1412,7 @@ qca8k_get_ethtool_stats(struct dsa_switch *ds, int port,
        struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
        const struct qca8k_mib_desc *mib;
        u32 reg, i, val;
-       u64 hi = 0;
+       u32 hi = 0;
        int ret;
 
        for (i = 0; i < ARRAY_SIZE(ar8327_mib); i++) {
@@ -1424,14 +1424,14 @@ qca8k_get_ethtool_stats(struct dsa_switch *ds, int port,
                        continue;
 
                if (mib->size == 2) {
-                       ret = qca8k_read(priv, reg + 4, (u32 *)&hi);
+                       ret = qca8k_read(priv, reg + 4, &hi);
                        if (ret < 0)
                                continue;
                }
 
                data[i] = val;
                if (mib->size == 2)
-                       data[i] |= hi << 32;
+                       data[i] |= (u64)hi << 32;
        }
 }