Skip to content

Commit 09c4a61

Browse files
Dan Carpenteralexandrebelloni
authored andcommitted
rtc: tps6594: Fix integer overflow on 32bit systems
The problem is this multiply in tps6594_rtc_set_offset() tmp = offset * TICKS_PER_HOUR; The "tmp" variable is an s64 but "offset" is a long in the (-277774)-277774 range. On 32bit systems a long can hold numbers up to approximately two billion. The number of TICKS_PER_HOUR is really large, (32768 * 3600) or roughly a hundred million. When you start multiplying by a hundred million it doesn't take long to overflow the two billion mark. Probably the safest way to fix this is to change the type of TICKS_PER_HOUR to long long because it's such a large number. Fixes: 9f67c1e ("rtc: tps6594: Add driver for TPS6594 RTC") Signed-off-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]>
1 parent 8c28c49 commit 09c4a61

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/rtc/rtc-tps6594.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#define MAX_OFFSET (277774)
3838

3939
// Number of ticks per hour
40-
#define TICKS_PER_HOUR (32768 * 3600)
40+
#define TICKS_PER_HOUR (32768 * 3600LL)
4141

4242
// Multiplier for ppb conversions
4343
#define PPB_MULT NANO

0 commit comments

Comments
 (0)