Skip to content

Commit 0336721

Browse files
fabiobaltierikartben
authored andcommitted
led: fix up the ENOSYS condition to pass coverity
The current ENOSYS check code can proceed for a driver that hypothetically implements the on() but not the off() function of vice versa, which would result in a null pointer dereference. This would be a weird use case but Coverity catches the situation, no harm in changing the ENOSYS check to fail if the on/off is half implemented, so let's change it to do that. Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
1 parent af43487 commit 0336721

File tree

1 file changed

+4
-3
lines changed
  • include/zephyr/drivers

1 file changed

+4
-3
lines changed

include/zephyr/drivers/led.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,10 @@ static inline int z_impl_led_set_brightness(const struct device *dev,
207207
const struct led_driver_api *api =
208208
(const struct led_driver_api *)dev->api;
209209

210-
if (api->set_brightness == NULL &&
211-
api->on == NULL && api->off == NULL) {
212-
return -ENOSYS;
210+
if (api->set_brightness == NULL) {
211+
if (api->on == NULL || api->off == NULL) {
212+
return -ENOSYS;
213+
}
213214
}
214215

215216
if (value > LED_BRIGTHNESS_MAX) {

0 commit comments

Comments
 (0)