From d5234c8b3de1211d98f03f7a36016adbe67cbf09 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Thu, 30 Apr 2020 06:52:33 -0400 Subject: [PATCH] target/arm: Rearrange disabled check for watchpoints Coverity rightly notes that ctz32(bas) on 0 will return 32, which makes the len calculation a BAD_SHIFT. A value of 0 in DBGWCR_EL1.BAS is reserved. Simply move the existing check we have for this case Backports commit ae1111d4def40c6f592c3a307c599272b778eb65 from qemu --- qemu/target/arm/helper.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/qemu/target/arm/helper.c b/qemu/target/arm/helper.c index 4106795a..2ff48ca7 100644 --- a/qemu/target/arm/helper.c +++ b/qemu/target/arm/helper.c @@ -6038,17 +6038,18 @@ void hw_watchpoint_update(ARMCPU *cpu, int n) int bas = extract64(wcr, 5, 8); int basstart; - if (bas == 0) { - /* This must act as if the watchpoint is disabled */ - return; - } - if (extract64(wvr, 2, 1)) { /* Deprecated case of an only 4-aligned address. BAS[7:4] are * ignored, and BAS[3:0] define which bytes to watch. */ bas &= 0xf; } + + if (bas == 0) { + /* This must act as if the watchpoint is disabled */ + return; + } + /* The BAS bits are supposed to be programmed to indicate a contiguous * range of bytes. Otherwise it is CONSTRAINED UNPREDICTABLE whether * we fire for each byte in the word/doubleword addressed by the WVR.