[PATCH] lib: sbi: fix trigger read range check
Anup Patel
anup at brainfault.org
Tue Nov 10 00:33:31 PST 2026
On Sat, Nov 7, 2026 at 11:33 AM Himanshu Chauhan
<himanshu.chauhan at oss.qualcomm.com> wrote:
>
> 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>
Good catch but Fixes tags are missing. I will add at the time of merging.
Also, trig_count can equal to total_trigs in sbi_dbtr_install_trig() and
sbi_dbtr_update_trig() so have squashed appropriate fix for these
functions in this patch as well.
Reviewed-by: Anup Patel <anup at brainfault.org>
Thanks,
Anup
> ---
> 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
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
More information about the opensbi
mailing list