mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 20:54:03 +02:00
leds: st1202: Validate pattern input before stopping the sequence
Input validation for pattern duration is performed inside the write loop, after the pattern sequence has already been stopped. If validation fails mid-loop the chip is left with the sequence stopped and partially written pattern data, with no recovery. Move all input validation before the mutex and before any hardware interaction, so an invalid input leaves the chip state unchanged. Signed-off-by: Manuel Fombuena <fombuena@outlook.com> Assisted-by: Claude:claude-sonnet-4-6 Link: https://patch.msgid.link/GV1PR08MB84975929B6ED7CDFBCEB7D76C5F52@GV1PR08MB8497.eurprd08.prod.outlook.com Signed-off-by: Lee Jones <lee@kernel.org>
This commit is contained in:
parent
9c019a8cb9
commit
fd2529ba8f
|
|
@ -228,6 +228,12 @@ static int st1202_led_pattern_set(struct led_classdev *ldev,
|
|||
if (len > ST1202_MAX_PATTERNS)
|
||||
return -EINVAL;
|
||||
|
||||
for (int patt = 0; patt < len; patt++) {
|
||||
if (pattern[patt].delta_t < ST1202_MILLIS_PATTERN_DUR_MIN ||
|
||||
pattern[patt].delta_t > ST1202_MILLIS_PATTERN_DUR_MAX)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
guard(mutex)(&chip->lock);
|
||||
|
||||
ret = st1202_write_reg(chip, ST1202_CONFIG_REG, ST1202_CONFIG_REG_SHFT);
|
||||
|
|
@ -235,10 +241,6 @@ static int st1202_led_pattern_set(struct led_classdev *ldev,
|
|||
return ret;
|
||||
|
||||
for (int patt = 0; patt < len; patt++) {
|
||||
if (pattern[patt].delta_t < ST1202_MILLIS_PATTERN_DUR_MIN ||
|
||||
pattern[patt].delta_t > ST1202_MILLIS_PATTERN_DUR_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
ret = st1202_pwm_pattern_write(chip, led->led_num, patt, pattern[patt].brightness);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user