[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 17/21] target/xtensa: Make use of 'segment' in pptlb helper less c
From: |
Peter Maydell |
Subject: |
[PULL 17/21] target/xtensa: Make use of 'segment' in pptlb helper less confusing |
Date: |
Tue, 30 Jul 2024 10:40:16 +0100 |
Coverity gets confused about the use of the 'segment' variable in the
pptlb helper function: it thinks that we can take a code path where
we first initialize it:
unsigned segment = XTENSA_MPU_PROBE_B; // 0x40000000
and then use that value as a shift count:
} else if (nhits == 1 && (env->sregs[MPUENB] & (1u << segment))) {
In fact this isn't possible, beacuse xtensa_mpu_lookup() is passed
'&segment', and it uses that as an output value, which it will always
set if it returns nonzero. But the way the code is currently written
is confusing to a human reader as well as to Coverity.
Instead of initializing 'segment' at the top of the function with a
value that's only used in the "nhits == 0" code path, use the
constant value directly in that code path, and don't initialize
segment. This matches the way we use xtensa_mpu_lookup() in its
other callsites in get_physical_addr_mpu().
Resolves: Coverity CID 1547589
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Acked-by: Max Filippov <jcmvbkbc@gmail.com>
Message-id: 20240723151454.1396826-1-peter.maydell@linaro.org
---
target/xtensa/mmu_helper.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/target/xtensa/mmu_helper.c b/target/xtensa/mmu_helper.c
index 997b21d3890..29b84d5dbf6 100644
--- a/target/xtensa/mmu_helper.c
+++ b/target/xtensa/mmu_helper.c
@@ -991,7 +991,7 @@ uint32_t HELPER(rptlb1)(CPUXtensaState *env, uint32_t s)
uint32_t HELPER(pptlb)(CPUXtensaState *env, uint32_t v)
{
unsigned nhits;
- unsigned segment = XTENSA_MPU_PROBE_B;
+ unsigned segment;
unsigned bg_segment;
nhits = xtensa_mpu_lookup(env->mpu_fg, env->config->n_mpu_fg_segments,
@@ -1005,7 +1005,7 @@ uint32_t HELPER(pptlb)(CPUXtensaState *env, uint32_t v)
xtensa_mpu_lookup(env->config->mpu_bg,
env->config->n_mpu_bg_segments,
v, &bg_segment);
- return env->config->mpu_bg[bg_segment].attr | segment;
+ return env->config->mpu_bg[bg_segment].attr | XTENSA_MPU_PROBE_B;
}
}
--
2.34.1
- [PULL 18/21] target/m68k: avoid shift into sign bit in dump_address_map(), (continued)
- [PULL 18/21] target/m68k: avoid shift into sign bit in dump_address_map(), Peter Maydell, 2024/07/30
- [PULL 19/21] target/i386: Remove dead assignment to ss in do_interrupt64(), Peter Maydell, 2024/07/30
- [PULL 20/21] target/sh4: Avoid shift into sign bit in update_itlb_use(), Peter Maydell, 2024/07/30
- [PULL 21/21] system/physmem: Where we assume we have a RAM MR, assert it, Peter Maydell, 2024/07/30
- [PULL 09/21] hw/misc/bcm2835_property: Avoid overflow in OTP access properties, Peter Maydell, 2024/07/30
- [PULL 11/21] hw/misc/bcm2835_property: Reduce scope of variables in mbox push function, Peter Maydell, 2024/07/30
- [PULL 10/21] hw/misc/bcm2835_property: Restrict scope of start_num, number, otp_row, Peter Maydell, 2024/07/30
- [PULL 12/21] target/arm: Don't assert for 128-bit tile accesses when SVL is 128, Peter Maydell, 2024/07/30
- [PULL 13/21] target/arm: Fix UMOPA/UMOPS of 16-bit values, Peter Maydell, 2024/07/30
- [PULL 16/21] target/tricore: Use unsigned types for bitops in helper_eq_b(), Peter Maydell, 2024/07/30
- [PULL 17/21] target/xtensa: Make use of 'segment' in pptlb helper less confusing,
Peter Maydell <=
- Re: [PULL 00/21] target-arm queue, Richard Henderson, 2024/07/30