[PATCH] lib: sbi: pmu: Return SBI_EINVAL if cidx_mask is 0 in ctr_cfg_match
James Raphael Tiovalen
jamestiotio at gmail.com
Mon May 12 00:16:48 PDT 2025
When configuring a matching counter, if the cidx_mask value being passed
in is 0, return the SBI_ERR_INVALID_PARAM error code.
This also aligns OpenSBI's behavior with KVM's.
Signed-off-by: James Raphael Tiovalen <jamestiotio at gmail.com>
---
lib/sbi/sbi_pmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c
index 5983a78..62ce770 100644
--- a/lib/sbi/sbi_pmu.c
+++ b/lib/sbi/sbi_pmu.c
@@ -840,7 +840,7 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask,
u32 event_code;
/* Do a basic sanity check of counter base & mask */
- if ((cidx_base + sbi_fls(cidx_mask)) >= total_ctrs)
+ if (!cidx_mask || ((cidx_base + sbi_fls(cidx_mask)) >= total_ctrs))
return SBI_EINVAL;
event_type = pmu_event_validate(phs, event_idx, event_data);
--
2.43.0
More information about the opensbi
mailing list