]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
video: backlight: pwm: avoid integer overflow in duty cycle calculation
authorMatthias Schiffer <matthias.schiffer@ew.tq-group.com>
Fri, 30 Jun 2023 12:30:07 +0000 (14:30 +0200)
committerAnatolij Gustschin <agust@denx.de>
Fri, 14 Jul 2023 16:12:37 +0000 (18:12 +0200)
The intermediate value could overflow for large periods and levels.

Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/video/pwm_backlight.c

index d7c096923b37288adc6ed450e036fe456ae4b07b..46c16a8f447bdcefd8a231a959348b7a648ff23b 100644 (file)
@@ -63,7 +63,7 @@ static int set_pwm(struct pwm_backlight_priv *priv)
        int ret;
 
        if (priv->period_ns) {
-               duty_cycle = priv->period_ns * (priv->cur_level - priv->min_level) /
+               duty_cycle = (u64)priv->period_ns * (priv->cur_level - priv->min_level) /
                        (priv->max_level - priv->min_level);
                ret = pwm_set_config(priv->pwm, priv->channel, priv->period_ns,
                                     duty_cycle);