Skip to contentSkip to conversation

leds: dac124s085: declare SPI command word as __le16

PATCH Applied Stepan Ionichev 2 participants 2 messages May 10 – May 20 LED

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds: dac124s085: declare SPI command word as __le16

dac124s085_set_brightness() builds a 16-bit SPI command word:

	u16 word;
	...
	word = cpu_to_le16(((led->id) << 14) | REG_WRITE_UPDATE |
			   (brightness & 0xfff));
	ret = spi_write(led->spi, (const u8 *)&word, sizeof(word));

cpu_to_le16() returns __le16, but the local 'word' is declared as plain u16, which sparse flags:

drivers/leds/leds-dac124s085.c:42:14: warning: incorrect type in assignment (different base types)

The bytes that hit the wire are correct because cpu_to_le16() does the right thing on either endianness, but mixing the annotated and unannotated types defeats sparse's __bitwise checking and would let a future reader treat the buffer as a host-endian u16 by mistake.

Declare 'word' as __le16 to match how it is built and consumed.

No functional change.

---
 drivers/leds/leds-dac124s085.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/leds/leds-dac124s085.c +1 -1
index cf5fb1195..192b43333 100644
@@ -35,7 +35,7 @@ static int dac124s085_set_brightness(struct led_classdev *ldev,
 {
 	struct dac124s085_led *led = container_of(ldev, struct dac124s085_led,
 						  ldev);
-	u16 word;
+	__le16 word;
 	int ret;
 
 	mutex_lock(&led->mutex);
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw

Re: (subset) [PATCH] leds: dac124s085: declare SPI command word as __le16

Quoted 9 lines · Stepan Ionichev

dac124s085_set_brightness() builds a 16-bit SPI command word:

	u16 word;
	...
	word = cpu_to_le16(((led->id) << 14) | REG_WRITE_UPDATE |
			   (brightness & 0xfff));
	ret = spi_write(led->spi, (const u8 *)&word, sizeof(word));

[...]

Applied, thanks!

[1/1] leds: dac124s085: declare SPI command word as __le16

      commit: e2e0784011e65dc2a0f83eed315c534a70ff5b68

--
Lee Jones [李琼斯]