429d5d50f056fc52e068cb02fde4483dc408e7b7
[openwrt/staging/aparcar.git] /
1 aFrom aa3d020b22cb844ab7bdbb9e5d861a64666e2b74 Mon Sep 17 00:00:00 2001
2 From: Dan Carpenter <dan.carpenter@oracle.com>
3 Date: Wed, 9 Jun 2021 12:52:12 +0300
4 Subject: [PATCH] net: dsa: qca8k: fix an endian bug in
5 qca8k_get_ethtool_stats()
6
7 The "hi" variable is a u64 but the qca8k_read() writes to the top 32
8 bits of it. That will work on little endian systems but it's a bit
9 subtle. It's cleaner to make declare "hi" as a u32. We will still need
10 to cast it when we shift it later on in the function but that's fine.
11
12 Fixes: 7c9896e37807 ("net: dsa: qca8k: check return value of read functions correctly")
13 Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
14 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
15 Signed-off-by: David S. Miller <davem@davemloft.net>
16 ---
17 drivers/net/dsa/qca8k.c | 6 +++---
18 1 file changed, 3 insertions(+), 3 deletions(-)
19
20 --- a/drivers/net/dsa/qca8k.c
21 +++ b/drivers/net/dsa/qca8k.c
22 @@ -1412,7 +1412,7 @@ qca8k_get_ethtool_stats(struct dsa_switc
23 struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
24 const struct qca8k_mib_desc *mib;
25 u32 reg, i, val;
26 - u64 hi = 0;
27 + u32 hi = 0;
28 int ret;
29
30 for (i = 0; i < ARRAY_SIZE(ar8327_mib); i++) {
31 @@ -1424,14 +1424,14 @@ qca8k_get_ethtool_stats(struct dsa_switc
32 continue;
33
34 if (mib->size == 2) {
35 - ret = qca8k_read(priv, reg + 4, (u32 *)&hi);
36 + ret = qca8k_read(priv, reg + 4, &hi);
37 if (ret < 0)
38 continue;
39 }
40
41 data[i] = val;
42 if (mib->size == 2)
43 - data[i] |= hi << 32;
44 + data[i] |= (u64)hi << 32;
45 }
46 }
47