net: dsa: qca8k: fix an endian bug in qca8k_get_ethtool_stats()
Subsystems (4)
PATCH 1/2 net: dsa: qca8k: fix an endian bug in qca8k_get_ethtool_stats()
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.
--- drivers/net/dsa/qca8k.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/dsa/qca8k.c +3 -3
@@ -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 ; } }
Signature · 1 line
2.30.2
PATCH 2/2 net: dsa: qca8k: check the correct variable in qca8k_set_mac_eee()
This code check "reg" but "ret" was intended so the error handling will never trigger.
--- drivers/net/dsa/qca8k.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/dsa/qca8k.c +1 -3
@@ -1454,10 +1454,8 @@ qca8k_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *eee)mutex_lock (&priv->reg_mutex); ret =qca8k_read (priv,QCA8K_REG_EEE_CTRL , ®); -if (reg <0 ) { - ret = reg; +if (ret <0 ) goto exit; - }if (eee->eee_enabled) reg |= lpi_en;
Signature · 1 line
2.30.2
Re: [PATCH 2/2 net-next] net: dsa: qca8k: check the correct variable in qca8k_set_mac_eee()
Quoted 6 lines · Dan Carpenter
This code check "reg" but "ret" was intended so the error handling will never trigger.
Fixes 7c9896e37807 ("net: dsa: qca8k: check return value of read functions correctly")Signed-off-by Dan Carpenter <[email protected]>---
Quoted 8 lines · Dan Carpenter
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 <[email protected]>---
This series was applied to netdev/net-next.git (refs/heads/master):
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
Quoted 9 lines · 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 <[email protected]>[...]
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