mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:46:17 +00:00
hw/misc/npcm_clk: Don't divide by zero when calculating frequency
If the guest misprograms the PLL registers to request a zero
divisor, we currently fall over with a division by zero:
../../hw/misc/npcm_clk.c:221:14: runtime error: division by zero
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../hw/misc/npcm_clk.c:221:14
Thread 1 "qemu-system-aar" received signal SIGFPE, Arithmetic exception.
0x00005555584d8f6d in npcm7xx_clk_update_pll (opaque=0x7fffed159a20) at ../../hw/misc/npcm_clk.c:221
221 freq /= PLLCON_INDV(con) * PLLCON_OTDV1(con) * PLLCON_OTDV2(con);
Avoid this by treating this invalid setting like a stopped clock
(setting freq to 0).
Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/549
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-id: 20251107150137.1353532-1-peter.maydell@linaro.org
(cherry picked from commit 5fc50b4ec8)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
committed by
Michael Tokarev
parent
842f4f8db3
commit
d0a90254f1
@@ -122,13 +122,14 @@ static void npcm7xx_clk_update_pll(void *opaque)
|
||||
{
|
||||
NPCM7xxClockPLLState *s = opaque;
|
||||
uint32_t con = s->clk->regs[s->reg];
|
||||
uint64_t freq;
|
||||
uint64_t freq, freq_div;
|
||||
|
||||
/* The PLL is grounded if it is not locked yet. */
|
||||
if (con & PLLCON_LOKI) {
|
||||
freq = clock_get_hz(s->clock_in);
|
||||
freq *= PLLCON_FBDV(con);
|
||||
freq /= PLLCON_INDV(con) * PLLCON_OTDV1(con) * PLLCON_OTDV2(con);
|
||||
freq_div = PLLCON_INDV(con) * PLLCON_OTDV1(con) * PLLCON_OTDV2(con);
|
||||
freq = freq_div ? freq / freq_div : 0;
|
||||
} else {
|
||||
freq = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user