From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 09/10] hw/misc/npcm_clk: Don't divide by zero when calculating frequency
Date: Fri, 14 Nov 2025 15:21:09 +0000 [thread overview]
Message-ID: <20251114152110.2547285-10-peter.maydell@linaro.org> (raw)
In-Reply-To: <20251114152110.2547285-1-peter.maydell@linaro.org>
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
---
hw/misc/npcm_clk.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/hw/misc/npcm_clk.c b/hw/misc/npcm_clk.c
index c48d40b4468..e202a8a2998 100644
--- a/hw/misc/npcm_clk.c
+++ b/hw/misc/npcm_clk.c
@@ -212,13 +212,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;
}
--
2.43.0
next prev parent reply other threads:[~2025-11-14 15:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 15:21 [PULL 00/10] target-arm queue Peter Maydell
2025-11-14 15:21 ` [PULL 01/10] MAINTAINERS: update maintainers for WHPX Peter Maydell
2025-11-14 15:21 ` [PULL 02/10] target/arm: Fix accidental write to TCG constant Peter Maydell
2025-11-14 15:21 ` [PULL 03/10] target/arm/cpu64: remove duplicate include Peter Maydell
2025-11-14 15:21 ` [PULL 04/10] hw/display/xlnx_dp.c: Don't abort on AUX FIFO overrun/underrun Peter Maydell
2025-11-14 15:21 ` [PULL 05/10] hw/display/xlnx_dp: Don't abort for unsupported graphics formats Peter Maydell
2025-11-14 15:21 ` [PULL 06/10] cxl: Clean up includes Peter Maydell
2025-11-14 15:21 ` [PULL 07/10] vfio: " Peter Maydell
2025-11-14 15:21 ` [PULL 08/10] tests: " Peter Maydell
2025-11-14 15:21 ` Peter Maydell [this message]
2025-11-14 15:21 ` [PULL 10/10] hw/audio/lm4549: Don't try to open a zero-frequency audio voice Peter Maydell
2025-11-14 19:08 ` [PULL 00/10] target-arm queue Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251114152110.2547285-10-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).