public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] video: backlight: pwm: avoid integer overflow in duty cycle calculation
@ 2023-06-30 12:30 Matthias Schiffer
  2023-07-03 13:30 ` Simon Glass
  2023-07-17 15:22 ` Anatolij Gustschin
  0 siblings, 2 replies; 3+ messages in thread
From: Matthias Schiffer @ 2023-06-30 12:30 UTC (permalink / raw)
  To: u-boot, Anatolij Gustschin; +Cc: u-boot, Matthias Schiffer

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(-)

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);
-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-07-17 15:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-30 12:30 [PATCH] video: backlight: pwm: avoid integer overflow in duty cycle calculation Matthias Schiffer
2023-07-03 13:30 ` Simon Glass
2023-07-17 15:22 ` Anatolij Gustschin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox