Skip to contentSkip to conversation

i2c: diolan-u2c: use get_unaligned_le32() in diolan_get_serial()

PATCH Felix Huang 1 participant 1 message Nov 28 1 message not in the archive I2C subsystem host drivers

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hi Guenter,

Thanks for the review.

You are right: dev->ibuffer is naturally aligned, so the commit message incorrectly suggests that the current access may be unaligned.

I will send a v2 that keeps the code change but rewords the commit message to focus on fixing the sparse "cast to restricted __le32" warning.

Best regards,
Felix Huang

Quoted 113 lines · Felix Huang

 Hi Guenter,

Thanks for the review.

You are right: dev->ibuffer is naturally aligned, so the commit message incorrectly suggests that the current access may be unaligned.

I will send a v2 that keeps the code change but rewords the commit message to focus on fixing the sparse "cast to restricted __le32" warning.

Best regards,

Felix Huang (he/him)
[email protected]

Please note: My working hours and your working hours may be different. Please do not feel obligated to reply outside your normal working hours.

On Nov 28, 2026, at 12:20 AM, Guenter Roeck <[email protected]> wrote:

On 11/27/26 18:33, Felix Huang via B4 Relay wrote:

From: Felix Huang <[email protected]>

Fix the following sparse warning by replacing le32_to_cpu(*(u32 *)...)

with get_unaligned_le32():

drivers/i2c/busses/i2c-diolan-u2c.c:290:26: warning: cast to restricted __le32

This preserves the exact little-endian conversion semantics while also

avoiding potential unaligned memory access on dev->ibuffer.

The buffer is allocated with kzalloc_obj and located DIOLAN_OUTBUF_LEN (128) bytes into the allocated data structure. It is never unaligned.

It is not my decision to make, but I would not accept this patch as-is because it falsely claims that there could be an unaligned buffer.

Guenter

---

 drivers/i2c/busses/i2c-diolan-u2c.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-diolan-u2c.c +0 -0

index d502f6e47..24db6d26c 100644

--- a/drivers/i2c/busses/i2c-diolan-u2c.c

+++ b/drivers/i2c/busses/i2c-diolan-u2c.c

drivers/i2c/busses/i2c-diolan-u2c.c +3 -3
@@ -16,6 +16,7 @@
 
 #include <linux/slab.h>
 
 #include <linux/usb.h>
 
 #include <linux/i2c.h>
 
+#include <linux/unaligned.h>
 
   #define DRIVER_NAME        "i2c-diolan-u2c"
 
 @@ -283,13 +284,12 @@ static void diolan_fw_version(struct i2c_diolan_u2c *dev)
 
 static void diolan_get_serial(struct i2c_diolan_u2c *dev)
 
 {
 
     int ret;
 
-    u32 serial;
 
       ret = diolan_usb_cmd(dev, CMD_GET_SERIAL, true);
 
     if (ret >= 4) {
 
-        serial = le32_to_cpu(*(u32 *)dev->ibuffer);
 
         dev_info(&dev->interface->dev,
 
-             "Diolan U2C serial number %u\n", serial);
 
+             "Diolan U2C serial number %u\n",
 
+             get_unaligned_le32(dev->ibuffer));
 
     }
 
 }
 
 ---

base-commit: f4585067150b85e33f60876149a6e742928da75e

change-id: 20261127-i2c-diolan-u2c-unaligned-2599ede88a92

Best regards,

--

Felix Huang <[email protected]>