Skip to content

Commit 69e7393

Browse files
fabiobaltierikartben
authored andcommitted
led: check for valid brightness range at API level
The API specifies that brightness is 0 to 100, no point checking it in the individual drivers. Signed-off-by: Fabio Baltieri <[email protected]>
1 parent 551c136 commit 69e7393

File tree

6 files changed

+5
-30
lines changed

6 files changed

+5
-30
lines changed

drivers/led/ht16k33.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ static int ht16k33_led_set_brightness(const struct device *dev, uint32_t led,
135135
uint8_t dim;
136136
uint8_t cmd;
137137

138-
if (value < dev_data->min_brightness ||
139-
value > dev_data->max_brightness) {
140-
return -EINVAL;
141-
}
142-
143138
dim = (value * (HT16K33_DIMMING_LEVELS - 1)) / dev_data->max_brightness;
144139
cmd = HT16K33_CMD_DIMMING_SET | dim;
145140

drivers/led/lp3943.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,6 @@ static int lp3943_led_set_brightness(const struct device *dev, uint32_t led,
174174
int ret;
175175
uint8_t reg, val, mode;
176176

177-
if (value < dev_data->min_brightness ||
178-
value > dev_data->max_brightness) {
179-
return -EINVAL;
180-
}
181-
182177
/* Use DIM0 for LEDs 0 to 7 and DIM1 for LEDs 8 to 15 */
183178
if (led < 8) {
184179
mode = LP3943_DIM0;

drivers/led/lp5562.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -613,11 +613,6 @@ static int lp5562_program_set_brightness(const struct device *dev,
613613
struct led_data *dev_data = &data->dev_data;
614614
uint8_t val;
615615

616-
if ((brightness < dev_data->min_brightness) ||
617-
(brightness > dev_data->max_brightness)) {
618-
return -EINVAL;
619-
}
620-
621616
val = (brightness * 0xFF) / dev_data->max_brightness;
622617

623618
return lp5562_program_command(dev, engine, command_index,
@@ -848,11 +843,6 @@ static int lp5562_led_set_brightness(const struct device *dev, uint32_t led,
848843
uint8_t val, reg;
849844
enum lp5562_led_sources current_source;
850845

851-
if ((value < dev_data->min_brightness) ||
852-
(value > dev_data->max_brightness)) {
853-
return -EINVAL;
854-
}
855-
856846
ret = lp5562_get_led_source(dev, led, &current_source);
857847
if (ret) {
858848
return ret;

drivers/led/pca9633.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@ static int pca9633_led_set_brightness(const struct device *dev, uint32_t led,
125125
struct led_data *dev_data = &data->dev_data;
126126
uint8_t val;
127127

128-
if (value < dev_data->min_brightness ||
129-
value > dev_data->max_brightness) {
130-
return -EINVAL;
131-
}
132-
133128
/* Set the LED brightness value */
134129
val = (value * 255U) / dev_data->max_brightness;
135130
if (i2c_reg_write_byte_dt(&config->i2c,

drivers/led/tlc59108.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,6 @@ static int tlc59108_led_set_brightness(const struct device *dev, uint32_t led,
146146
return -EINVAL;
147147
}
148148

149-
if (value < dev_data->min_brightness ||
150-
value > dev_data->max_brightness) {
151-
return -EINVAL;
152-
}
153-
154149
/* Set the LED brightness value */
155150
val = (value * 255U) / dev_data->max_brightness;
156151
if (i2c_reg_write_byte_dt(&config->i2c, TLC59108_PWM_BASE + led, val)) {

include/zephyr/drivers/led.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ static inline int z_impl_led_set_brightness(const struct device *dev,
209209
if (api->set_brightness == NULL) {
210210
return -ENOSYS;
211211
}
212+
213+
if (value > LED_BRIGTHNESS_MAX) {
214+
return -EINVAL;
215+
}
216+
212217
return api->set_brightness(dev, led, value);
213218
}
214219

0 commit comments

Comments
 (0)