Skip to contentSkip to conversation

Fix 'assignment to __be16' warning

PATCH In review Bence Csókás 3 participants 3 messages Apr 12, 2021 – Apr 15, 2021

Subsystems (2)
lore
Share & tools
lore

Bence Csókás

author maintainer
#0 lore raw

PATCH 1/1 Fix 'assignment to __be16' warning

While the preamble field _is_ technically big-endian, its value is always 0x2A2A, which is the same in either endianness, therefore it should be u16 instead.

---
 drivers/i2c/busses/i2c-cp2615.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-cp2615.c +3 -1
index 78cfecd1ea76..2824f4ba7131 100644
@@ -38,7 +38,9 @@ enum cp2615_iop_msg_type {
 };
 
 struct __packed cp2615_iop_msg {
-	__be16 preamble, length, msg;
+	/* always 0x2A2A, which is the same in either endianness */
+	u16 preamble;
+	__be16 length, msg;
 	u8 data[MAX_IOP_PAYLOAD_SIZE];
 };
 
Signature · 1 line
2.31.0
#1 lore raw

Hi Bence,

Quoted 2 lines · Bence Csókás

While the preamble field _is_ technically big-endian, its value is always 0x2A2A, which is the same in either endianness, therefore it should be u16 instead.

Why should it be u16? I don't see it.

I thought the fix would be to add the suffix 'U' to 0x2A2A when it is assigned to preamble?

Also, please use "i2c: cp2615: <patch header>" in the $subject

Happy hacking,

Wolfram

#2 lore raw
In reply to Bence Csókás
Quoted 2 lines · Bence Csókás

While the preamble field _is_ technically big-endian, its value is always 0x2A2A, which is the same in either endianness, therefore it should be u16 instead.

Just replace the assignment with htons(0x2A2A) and be done with that - it's a constant expression and compiler will yield the same assembler.