diff mbox series

video: backlight: pwm: avoid integer overflow in duty cycle calculation

Message ID 20230630123007.1725726-1-matthias.schiffer@ew.tq-group.com
State Accepted
Commit 533ad9dcda38a78c7965e9cea8a05c80d18449e4
Delegated to: Anatolij Gustschin
Headers show
Series video: backlight: pwm: avoid integer overflow in duty cycle calculation | expand

Commit Message

Matthias Schiffer June 30, 2023, 12:30 p.m. UTC
The intermediate value could overflow for large periods and levels.

Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
---
 drivers/video/pwm_backlight.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Glass July 3, 2023, 1:30 p.m. UTC | #1
On Fri, 30 Jun 2023 at 13:38, Matthias Schiffer
<matthias.schiffer@ew.tq-group.com> wrote:
>
> The intermediate value could overflow for large periods and levels.
>
> Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
> ---
>  drivers/video/pwm_backlight.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Anatolij Gustschin July 17, 2023, 3:22 p.m. UTC | #2
On Fri, 30 Jun 2023 14:30:07 +0200
Matthias Schiffer matthias.schiffer@ew.tq-group.com wrote:

> The intermediate value could overflow for large periods and levels.
> 
> Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
> ---

applied to u-boot-video/master, thanks!

--
Anatolij
diff mbox series

Patch

diff --git a/drivers/video/pwm_backlight.c b/drivers/video/pwm_backlight.c
index d7c096923b3..46c16a8f447 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);