leds: pattern trigger -- check pattern for validity

Don't allow invalid brightness in the pattern.

Signed-off-by: Pavel Machek <pavel@ucw.cz>
This commit is contained in:
Pavel Machek 2020-07-24 12:43:47 +02:00
parent c543733815
commit feff72735b

View File

@ -227,10 +227,12 @@ static int pattern_trig_store_patterns_string(struct pattern_trig_data *data,
while (offset < count - 1 && data->npatterns < MAX_PATTERNS) {
cr = 0;
ccount = sscanf(buf + offset, "%d %u %n",
ccount = sscanf(buf + offset, "%u %u %n",
&data->patterns[data->npatterns].brightness,
&data->patterns[data->npatterns].delta_t, &cr);
if (ccount != 2) {
if (ccount != 2 ||
data->patterns[data->npatterns].brightness > data->led_cdev->max_brightness) {
data->npatterns = 0;
return -EINVAL;
}