[PATCH v2 12/13] leds: st1202: Cap the channel current in st1202_led_set()
From: Manuel Fombuena
Date: Tue Sep 15 2026 - 09:02:55 EST
st1202_led_set() writes the requested brightness straight into the 8-bit
channel current register. The LED core limits brightness to
max_brightness, which comes from the device tree max-brightness property
and has no upper bound, so on a board declaring more than 255 a
brightness of 256 reaches the register as 0 and turns the LED off, and
larger values wrap around.
Cap the value at U8_MAX, the width of the register, so anything above it
drives the channel at full current. The pattern and blink paths already
cap the current they program the same way.
Fixes: 259230378c65 ("leds: Add LED1202 I2C driver")
Signed-off-by: Manuel Fombuena <fombuena@xxxxxxxxxxx>
Assisted-by: LLM
---
drivers/leds/leds-st1202.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/leds/leds-st1202.c b/drivers/leds/leds-st1202.c
index 39129206b78d..5e4a8b80cfe4 100644
--- a/drivers/leds/leds-st1202.c
+++ b/drivers/leds/leds-st1202.c
@@ -207,7 +207,8 @@ static int st1202_led_set(struct led_classdev *ldev, enum led_brightness value)
return ret;
}
- ret = st1202_write_reg(chip, ST1202_ILED_REG0 + led->led_num, value);
+ ret = st1202_write_reg(chip, ST1202_ILED_REG0 + led->led_num,
+ min_t(unsigned int, value, U8_MAX));
if (ret)
return ret;
--
2.55.0