public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: amd756: Fix endianness handling for word data
@ 2025-01-01 10:34 Atharva Tiwari
  2025-01-03 23:18 ` Andi Shyti
  2025-01-03 23:32 ` Andi Shyti
  0 siblings, 2 replies; 11+ messages in thread
From: Atharva Tiwari @ 2025-01-01 10:34 UTC (permalink / raw)
  Cc: evepolonium, kernel test robot, Jean Delvare, Andi Shyti,
	linux-i2c, linux-kernel

Ensure correct handling of "endianness"
for word-sized data in amd756_access

 - Convert word data into little-endian using cpu_to_le16
 - Convert word data from little-endian
   to cpu native format using le16_to_cpu

This fixes poteential issues on big-endian systems and
ensure proper byte ordering for SMBus word transacitions

and you would be thinking why did i resend the patch
it is because kernel test robot
noticed a few warning so i fixed them

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202412311145.AKMzVNw4-lkp@intel.com/

Signed-off-by: Atharva Tiwari <evepolonium@gmail.com>
---
 drivers/i2c/busses/i2c-amd756.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index fa0d5a2c3732..e551d63e96b1 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -31,6 +31,7 @@
 #include <linux/i2c.h>
 #include <linux/acpi.h>
 #include <linux/io.h>
+#include <linux/byteorder/generic.h>
 
 /* AMD756 SMBus address offsets */
 #define SMB_ADDR_OFFSET		0xE0
@@ -211,7 +212,7 @@ static s32 amd756_access(struct i2c_adapter * adap, u16 addr,
 		       SMB_HOST_ADDRESS);
 		outb_p(command, SMB_HOST_COMMAND);
 		if (read_write == I2C_SMBUS_WRITE)
-			outw_p(data->word, SMB_HOST_DATA);	/* TODO: endian???? */
+			outw_p(cpu_to_le16((u16)data->word), SMB_HOST_DATA);
 		size = AMD756_WORD_DATA;
 		break;
 	case I2C_SMBUS_BLOCK_DATA:
@@ -256,7 +257,7 @@ static s32 amd756_access(struct i2c_adapter * adap, u16 addr,
 		data->byte = inw_p(SMB_HOST_DATA);
 		break;
 	case AMD756_WORD_DATA:
-		data->word = inw_p(SMB_HOST_DATA);	/* TODO: endian???? */
+		data->word = (u16)le16_to_cpu(inw_p(SMB_HOST_DATA));
 		break;
 	case AMD756_BLOCK_DATA:
 		data->block[0] = inw_p(SMB_HOST_DATA) & 0x3f;
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [PATCH] i2c: amd756: Fix endianness handling for word data
@ 2024-12-27 13:22 Atharva Tiwari
  2024-12-30  2:03 ` Andi Shyti
  0 siblings, 1 reply; 11+ messages in thread
From: Atharva Tiwari @ 2024-12-27 13:22 UTC (permalink / raw)
  Cc: evepolonium, Jean Delvare, Andi Shyti, linux-i2c, linux-kernel

Ensure correct handling of "endianness"
for word-sized data in amd756_access

 - Convert word data into little-endian using cpu_to_le16
 - Convert word data from little-endian 
   to cpu native format using le16_to_cpu

This fixes poteential issues on big-endian systems and
ensure proper byte ordering for SMBus word transacitions

Signed-off-by: Atharva Tiwari <evepolonium@gmail.com>
---
 drivers/i2c/busses/i2c-amd756.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index fa0d5a2c3732..f6fe4c32af04 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -31,6 +31,7 @@
 #include <linux/i2c.h>
 #include <linux/acpi.h>
 #include <linux/io.h>
+#include <linux/byteorder/generic.h>
 
 /* AMD756 SMBus address offsets */
 #define SMB_ADDR_OFFSET		0xE0
@@ -211,7 +212,7 @@ static s32 amd756_access(struct i2c_adapter * adap, u16 addr,
 		       SMB_HOST_ADDRESS);
 		outb_p(command, SMB_HOST_COMMAND);
 		if (read_write == I2C_SMBUS_WRITE)
-			outw_p(data->word, SMB_HOST_DATA);	/* TODO: endian???? */
+			outw_p(cpu_to_le16(data->word), SMB_HOST_DATA);
 		size = AMD756_WORD_DATA;
 		break;
 	case I2C_SMBUS_BLOCK_DATA:
@@ -256,7 +257,7 @@ static s32 amd756_access(struct i2c_adapter * adap, u16 addr,
 		data->byte = inw_p(SMB_HOST_DATA);
 		break;
 	case AMD756_WORD_DATA:
-		data->word = inw_p(SMB_HOST_DATA);	/* TODO: endian???? */
+		data->word = le16_to_cpu(inw_p(SMB_HOST_DATA));
 		break;
 	case AMD756_BLOCK_DATA:
 		data->block[0] = inw_p(SMB_HOST_DATA) & 0x3f;
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-01-09  9:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-01 10:34 [PATCH] i2c: amd756: Fix endianness handling for word data Atharva Tiwari
2025-01-03 23:18 ` Andi Shyti
2025-01-03 23:28   ` Wolfram Sang
2025-01-03 23:50     ` Andi Shyti
2025-01-04 10:32       ` Wolfram Sang
2025-01-07 18:57         ` Andi Shyti
2025-01-09  9:23           ` Wolfram Sang
2025-01-03 23:32 ` Andi Shyti
2025-01-04  3:46   ` Andi Shyti
  -- strict thread matches above, loose matches on Subject: below --
2024-12-27 13:22 Atharva Tiwari
2024-12-30  2:03 ` Andi Shyti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox