[PATCH] lib: sbi: fix trigger read range check

Himanshu Chauhan himanshu.chauhan at oss.qualcomm.com
Fri Nov 6 22:03:25 PST 2026


sbi_dbtr_read_trig() rejects ranges ending exactly at total_trigs
because it treats trig_idx_base + trig_count == total_trigs as
out of range. This breaks the corner case where supervisor
software reads the last trigger by asking for base total_trigs - 1
and count 1.

Validate the base first, then compare trig_count against
total_trigs - trig_idx_base. This permits exact-end ranges and avoids
relying on unsigned addition that could overflow for a bad count.

Signed-off-by: Himanshu Chauhan <himanshu.chauhan at oss.qualcomm.com>
---
 lib/sbi/sbi_dbtr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c
index 5f66b641..967d6af7 100644
--- a/lib/sbi/sbi_dbtr.c
+++ b/lib/sbi/sbi_dbtr.c
@@ -649,7 +649,7 @@ int sbi_dbtr_read_trig(unsigned long smode,
 		return SBI_ERR_FAILED;
 
 	if (trig_idx_base >= hs->total_trigs ||
-	    trig_count >= hs->total_trigs - trig_idx_base)
+	    trig_count > hs->total_trigs - trig_idx_base)
 		return SBI_ERR_BAD_RANGE;
 
 	if (sbi_dbtr_shmem_disabled(hs))
-- 
2.43.0




More information about the opensbi mailing list