[PATCH net 6/6] net: dsa: ksz: fix wrong read cast to u64

From: Gilles DOFFE
Date: Wed Jan 13 2021 - 07:56:11 EST


'(u64)*value' casts a u32 to a u64. So depending on endianness,
LSB or MSB is lost.
The pointer needs to be cast to read the full u64:
'*((u64 *)value)'

Signed-off-by: Gilles DOFFE <gilles.doffe@xxxxxxxxxxxxxxxxxxxx>
---
drivers/net/dsa/microchip/ksz_common.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 44e97c55c2da..492dcb2011f1 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -213,7 +213,7 @@ static inline int ksz_read64(struct ksz_device *dev, u32 reg, u64 *val)
/* Ick! ToDo: Add 64bit R/W to regmap on 32bit systems */
value[0] = swab32(value[0]);
value[1] = swab32(value[1]);
- *val = swab64((u64)*value);
+ *val = swab64((((u64)value[1]) << 32) | value[0]);
}

return ret;
--
2.25.1