Skip to content

Commit 593b910

Browse files
Tigran Sogomonianpm215
authored andcommitted
hw/misc: cast rpm to uint64_t
The value of an arithmetic expression 'rpm * NPCM7XX_MFT_PULSE_PER_REVOLUTION' is a subject to overflow because its operands are not cast to a larger data type before performing arithmetic. Thus, need to cast rpm to uint64_t. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Tigran Sogomonian <[email protected]> Reviewed-by: Patrick Leis <[email protected]> Reviewed-by: Hao Wu <[email protected]> Message-id: [email protected] Signed-off-by: Peter Maydell <[email protected]>
1 parent 906853e commit 593b910

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

hw/misc/npcm7xx_mft.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ static NPCM7xxMFTCaptureState npcm7xx_mft_compute_cnt(
172172
* RPM = revolution/min. The time for one revlution (in ns) is
173173
* MINUTE_TO_NANOSECOND / RPM.
174174
*/
175-
count = clock_ns_to_ticks(clock, (60 * NANOSECONDS_PER_SECOND) /
176-
(rpm * NPCM7XX_MFT_PULSE_PER_REVOLUTION));
175+
count = clock_ns_to_ticks(clock,
176+
(uint64_t)(60 * NANOSECONDS_PER_SECOND) /
177+
((uint64_t)rpm * NPCM7XX_MFT_PULSE_PER_REVOLUTION));
177178
}
178179

179180
if (count > NPCM7XX_MFT_MAX_CNT) {

0 commit comments

Comments
 (0)