@@ -27,6 +27,7 @@
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/module.h>
+#include <asm/div64.h>
#include "cx88.h"
#include <media/rc-core.h>
@@ -522,9 +523,16 @@ void cx88_ir_irq(struct cx88_core *core)
init_ir_raw_event(&ev);
for (todo = 32; todo > 0; todo -= bits) {
- ev.pulse = samples & 0x80000000 ? false : true;
+ u64 duration = NSEC_PER_SEC;
+
bits = min(todo, 32U - fls(ev.pulse ? samples : ~samples));
- ev.duration = (bits * NSEC_PER_SEC) / (1000 * ir_samplerate);
+
+ /* Avoid 32-bits overflow */
+ duration = bits * duration;
+ do_div(duration, 1000 * ir_samplerate);
+
+ ev.pulse = samples & 0x80000000 ? false : true;
+ ev.duration = duration;
ir_raw_event_store_with_filter(ir->dev, &ev);
samples <<= bits;
}