Skip to contentSkip to conversation

i2c: diolan-u2c: Use __le32 when reading serial number

PATCH Applied Felix Huang 3 participants 3 messages Nov 28 – Nov 30

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 i2c: diolan-u2c: Use __le32 when reading serial number

Sparse reports:

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

Cast the serial-number buffer pointer to __le32 before passing it to le32_to_cpu(). This makes the byte-order conversion explicit and silences the sparse warning.

---
Changes in v3:
- Cast the serial-number buffer pointer to __le32 before passing it to le32_to_cpu(), as suggested by Guenter Roeck.
- Keep the serial variable and do not use get_unaligned_le32().
- Reword the commit message to accurately describe the motivation.
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Reword the commit message to accurately describe the motivation.
- The serial-number buffer is naturally aligned; do not claim that the
existing access may be unaligned.
- Focus on fixing the sparse "cast to restricted __le32" warning.
- Link to v1: https://patch.msgid.link/[email protected]

To: Guenter Roeck <[email protected]>
To: Andi Shyti <[email protected]>
Cc: [email protected]

---
 drivers/i2c/busses/i2c-diolan-u2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-diolan-u2c.c +1 -1
index d502f6e47..77471011f 100644
@@ -287,7 +287,7 @@ static void diolan_get_serial(struct i2c_diolan_u2c *dev)
 
 	ret = diolan_usb_cmd(dev, CMD_GET_SERIAL, true);
 	if (ret >= 4) {
-		serial = le32_to_cpu(*(u32 *)dev->ibuffer);
+		serial = le32_to_cpu(*(__le32 *)dev->ibuffer);
 		dev_info(&dev->interface->dev,
 			 "Diolan U2C serial number %u\n", serial);
 	}

---
base-commit: f4585067150b85e33f60876149a6e742928da75e
change-id: 20261127-i2c-diolan-u2c-unaligned-2599ede88a92

Best regards,

Signature · 1 line
Felix Huang <[email protected]>
maintainer Reviewed-by on v3 1/1
#1 lore raw
Quoted 4 lines · On 11/28/26 07:39, Felix Huang via B4 Relay wrote:

From: Felix Huang <[email protected]>

Sparse reports:

Quoted 8 lines

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

Cast the serial-number buffer pointer to __le32 before passing it to le32_to_cpu(). This makes the byte-order conversion explicit and silences the sparse warning.

Quoted 43 lines

---
Changes in v3:
- Cast the serial-number buffer pointer to __le32 before passing it to le32_to_cpu(), as suggested by Guenter Roeck.
- Keep the serial variable and do not use get_unaligned_le32().
- Reword the commit message to accurately describe the motivation.
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Reword the commit message to accurately describe the motivation.
- The serial-number buffer is naturally aligned; do not claim that the
existing access may be unaligned.
- Focus on fixing the sparse "cast to restricted __le32" warning.
- Link to v1: https://patch.msgid.link/[email protected]

To: Guenter Roeck <[email protected]>
To: Andi Shyti <[email protected]>
Cc: [email protected]

---
  drivers/i2c/busses/i2c-diolan-u2c.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-diolan-u2c.c +1 -2
index d502f6e47..77471011f 100644
@@ -287,7 +287,7 @@ static void diolan_get_serial(struct i2c_diolan_u2c *dev)
 
  	ret = diolan_usb_cmd(dev, CMD_GET_SERIAL, true);
  	if (ret >= 4) {
-		serial = le32_to_cpu(*(u32 *)dev->ibuffer);
+		serial = le32_to_cpu(*(__le32 *)dev->ibuffer);
  		dev_info(&dev->interface->dev,
  			 "Diolan U2C serial number %u\n", serial);
  	}
 
---

base-commit: f4585067150b85e33f60876149a6e742928da75e
change-id: 20261127-i2c-diolan-u2c-unaligned-2599ede88a92

Best regards,
--
Felix Huang <[email protected]>

maintainer Applied
#2 lore raw
In reply to Felix Huang

Hi Felix,

Quoted 10 lines · Felix Huang

Sparse reports:

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

Cast the serial-number buffer pointer to __le32 before passing it to le32_to_cpu(). This makes the byte-order conversion explicit and silences the sparse warning.

pushed to i2c/i2c.

Thanks,
Andi