public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] bugfix i.mx6 pwm: prevent overflow of period_c * duty_ns
@ 2015-05-06  7:57 Brecht Neyrinck
  2015-05-06  8:14 ` Heiko Schocher
  2015-05-15  8:06 ` Stefano Babic
  0 siblings, 2 replies; 3+ messages in thread
From: Brecht Neyrinck @ 2015-05-06  7:57 UTC (permalink / raw)
  To: u-boot

Prevent overflow by casting duty_ns to ull first. This bug came up when trying to create a 200 Hz PWM

Signed-off-by: Brecht Neyrinck <bnrn@psicontrol.com>
---
 drivers/pwm/pwm-imx-util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pwm/pwm-imx-util.c b/drivers/pwm/pwm-imx-util.c
index f1d0b35..79d86028 100644
--- a/drivers/pwm/pwm-imx-util.c
+++ b/drivers/pwm/pwm-imx-util.c
@@ -56,7 +56,7 @@ int pwm_imx_get_parms(int period_ns, int duty_ns, unsigned long *period_c,
 	*prescale = *period_c / 0x10000 + 1;
 
 	*period_c /= *prescale;
-	c = (unsigned long long)(*period_c * duty_ns);
+	c = *period_c * (unsigned long long)duty_ns;
 	do_div(c, period_ns);
 	*duty_c = c;
 
-- 
1.8.2.3




**** DISCLAIMER **** The contents of this e-mail are intended for the named
addressee only. It contains information which may be confidential and which
may also be privileged. Unless you are the named addressee (or authorised
to receive for the addressee) you may not copy or use it, or disclose it to
anyone else. If you received it in error please notify us immediately and then
destroy it. Further, we make every effort to keep our network free from
viruses. However, you do need to verify that this email and any attachments
are free of viruses as we can take no responsibility for any computer virus
which might be transferred by way of this e-mail.

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

end of thread, other threads:[~2015-05-15  8:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-06  7:57 [U-Boot] [PATCH] bugfix i.mx6 pwm: prevent overflow of period_c * duty_ns Brecht Neyrinck
2015-05-06  8:14 ` Heiko Schocher
2015-05-15  8:06 ` Stefano Babic

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