From: Matthias Schiffer Date: Fri, 30 Jun 2023 12:30:07 +0000 (+0200) Subject: video: backlight: pwm: avoid integer overflow in duty cycle calculation X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=533ad9dcda38a78c7965e9cea8a05c80d18449e4;p=u-boot.git video: backlight: pwm: avoid integer overflow in duty cycle calculation The intermediate value could overflow for large periods and levels. Signed-off-by: Matthias Schiffer Reviewed-by: Simon Glass --- diff --git a/drivers/video/pwm_backlight.c b/drivers/video/pwm_backlight.c index d7c096923b..46c16a8f44 100644 --- a/drivers/video/pwm_backlight.c +++ b/drivers/video/pwm_backlight.c @@ -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);