diff mbox series

[1/2,net-next] net: dsa: qca8k: fix an endian bug in qca8k_get_ethtool_stats()

Message ID YMCPTLkZumD3Vv/X@mwanda (mailing list archive)
State Accepted
Commit aa3d020b22cb844ab7bdbb9e5d861a64666e2b74
Delegated to: Netdev Maintainers
Headers show
Series [1/2,net-next] net: dsa: qca8k: fix an endian bug in qca8k_get_ethtool_stats() | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 24 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Dan Carpenter June 9, 2021, 9:52 a.m. UTC
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>
---
 drivers/net/dsa/qca8k.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Vladimir Oltean June 9, 2021, 1:44 p.m. UTC | #1
On Wed, Jun 09, 2021 at 12:52:12PM +0300, Dan Carpenter wrote:
> 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>
patchwork-bot+netdevbpf@kernel.org June 9, 2021, 9:20 p.m. UTC | #2
Hello:

This series was applied to netdev/net-next.git (refs/heads/master):

On Wed, 9 Jun 2021 12:52:12 +0300 you wrote:
> 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>
> 
> [...]

Here is the summary with links:
  - [1/2,net-next] net: dsa: qca8k: fix an endian bug in qca8k_get_ethtool_stats()
    https://git.kernel.org/netdev/net-next/c/aa3d020b22cb
  - [2/2,net-next] net: dsa: qca8k: check the correct variable in qca8k_set_mac_eee()
    https://git.kernel.org/netdev/net-next/c/3d0167f2a627

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
diff mbox series

Patch

diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
index 6fe963ba23e8..9df3514d1ff2 100644
--- a/drivers/net/dsa/qca8k.c
+++ b/drivers/net/dsa/qca8k.c
@@ -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;
 	}
 }