mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-11-20 10:32:19 +00:00
lib: sbi_hart: Retrun zero length of mhpmcounter when probing failed
If writing access is not allowed, it will raise a trap, but we increase the number of allowed bits to 32 in this approach, which isn't right. There must be a write of 0. Move the operation of increasing allowed bits into the 'if' condition. Signed-off-by: Evgenii Prokopiev <eestelle0626@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20260910182026.6776-1-eestelle0626@gmail.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
1 parent
3a51dc070e
commit
d28bc6f898
1 file changed
+4
-3
+4
-3
@@ -451,8 +451,9 @@ static int hart_mhpm_get_allowed_bits(void)
|
|||||||
csr_write(CSR_MHPMCOUNTER3, 0);
|
csr_write(CSR_MHPMCOUNTER3, 0);
|
||||||
if (trap.cause)
|
if (trap.cause)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
num_bits = sbi_fls(val) + 1;
|
num_bits = sbi_fls(val) + 1;
|
||||||
|
}
|
||||||
#if __riscv_xlen == 32
|
#if __riscv_xlen == 32
|
||||||
csr_write_allowed(CSR_MHPMCOUNTER3H, &trap, val);
|
csr_write_allowed(CSR_MHPMCOUNTER3H, &trap, val);
|
||||||
if (!trap.cause) {
|
if (!trap.cause) {
|
||||||
@@ -460,9 +461,9 @@ static int hart_mhpm_get_allowed_bits(void)
|
|||||||
csr_write(CSR_MHPMCOUNTER3H, 0);
|
csr_write(CSR_MHPMCOUNTER3H, 0);
|
||||||
if (trap.cause)
|
if (trap.cause)
|
||||||
return num_bits;
|
return num_bits;
|
||||||
}
|
|
||||||
num_bits += sbi_fls(val) + 1;
|
|
||||||
|
|
||||||
|
num_bits += sbi_fls(val) + 1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return num_bits;
|
return num_bits;
|
||||||
|
|||||||
Reference in new issue
Block a user