drivers: led_pwm: fix overflow in set_brightness
The set_brightness function of the led_pwm driver uses a default PWM period (defined in the pwms DT property) to compute a pulse passed to the pwm_set_pulse_dt function. If this default period is greater than 2^32/100 nanoseconds (about 43 milliseconds) then the calculation may overflow. This patch prevents this overflow by running the pulse computation under a cast with a larger type (uint64_t). Reported-by: Scott Worley <scott.worley@microchip.com> Signed-off-by: Simon Guinot <simon.guinot@seagate.com>
This commit is contained in:
parent
64ec7e18c8
commit
a4645908ee
1 changed files with 1 additions and 1 deletions
|
@ -65,7 +65,7 @@ static int led_pwm_set_brightness(const struct device *dev,
|
||||||
dt_led = &config->led[led];
|
dt_led = &config->led[led];
|
||||||
|
|
||||||
return pwm_set_pulse_dt(&config->led[led],
|
return pwm_set_pulse_dt(&config->led[led],
|
||||||
dt_led->period * value / 100);
|
(uint32_t) ((uint64_t) dt_led->period * value / 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int led_pwm_on(const struct device *dev, uint32_t led)
|
static int led_pwm_on(const struct device *dev, uint32_t led)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue