[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 02/11] hw/misc: cast rpm to uint64_t
From: |
Peter Maydell |
Subject: |
[PULL 02/11] hw/misc: cast rpm to uint64_t |
Date: |
Mon, 13 Jan 2025 13:53:59 +0000 |
From: Tigran Sogomonian <tsogomonian@astralinux.ru>
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 <tsogomonian@astralinux.ru>
Reviewed-by: Patrick Leis <venture@google.com>
Reviewed-by: Hao Wu <wuhaotsh@google.com>
Message-id: 20241226130311.1349-1-tsogomonian@astralinux.ru
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/misc/npcm7xx_mft.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/hw/misc/npcm7xx_mft.c b/hw/misc/npcm7xx_mft.c
index 9fcc69fe5c5..e565cac05d8 100644
--- a/hw/misc/npcm7xx_mft.c
+++ b/hw/misc/npcm7xx_mft.c
@@ -172,8 +172,9 @@ static NPCM7xxMFTCaptureState npcm7xx_mft_compute_cnt(
* RPM = revolution/min. The time for one revlution (in ns) is
* MINUTE_TO_NANOSECOND / RPM.
*/
- count = clock_ns_to_ticks(clock, (60 * NANOSECONDS_PER_SECOND) /
- (rpm * NPCM7XX_MFT_PULSE_PER_REVOLUTION));
+ count = clock_ns_to_ticks(clock,
+ (uint64_t)(60 * NANOSECONDS_PER_SECOND) /
+ ((uint64_t)rpm * NPCM7XX_MFT_PULSE_PER_REVOLUTION));
}
if (count > NPCM7XX_MFT_MAX_CNT) {
--
2.34.1
- [PULL 00/11] target-arm queue, Peter Maydell, 2025/01/13
- [PULL 04/11] tests/qtest/boot-serial-test: Reduce for() loop in PL011 tests, Peter Maydell, 2025/01/13
- [PULL 01/11] hw/arm_sysctl: fix extracting 31th bit of val, Peter Maydell, 2025/01/13
- [PULL 08/11] target/arm: add new property to select pauth-qarma5, Peter Maydell, 2025/01/13
- [PULL 05/11] tests/qtest/boot-serial-test: Reorder pair of instructions in PL011 test, Peter Maydell, 2025/01/13
- [PULL 02/11] hw/misc: cast rpm to uint64_t,
Peter Maydell <=
- [PULL 06/11] tests/qtest/boot-serial-test: Initialize PL011 Control register, Peter Maydell, 2025/01/13
- [PULL 10/11] target/arm: change default pauth algorithm to impdef, Peter Maydell, 2025/01/13
- [PULL 03/11] tests/qtest/boot-serial-test: Improve ASM comments of PL011 tests, Peter Maydell, 2025/01/13
- [PULL 11/11] docs/system/arm/virt: mention specific migration information, Peter Maydell, 2025/01/13
- [PULL 09/11] tests/tcg/aarch64: force qarma5 for pauth-3 test, Peter Maydell, 2025/01/13
- [PULL 07/11] target/arm: Move minor arithmetic helpers out of helper.c, Peter Maydell, 2025/01/13
- Re: [PULL 00/11] target-arm queue, Stefan Hajnoczi, 2025/01/13