lib: sbi: Use mask to check the free bit during trigger allocation
authorHimanshu Chauhan <hchauhan@ventanamicro.com>
Tue, 2 Jan 2024 16:46:24 +0000 (22:16 +0530)
committerAnup Patel <anup@brainfault.org>
Mon, 5 Feb 2024 04:53:01 +0000 (10:23 +0530)
The trigger allocation function uses bit shift instead of mask to check the
mapped status of the triggers. This causes index 0 to be return always. As a
result, the older triggers are overwritten.

Use the mask for MAPPED field in state word to check if the trigger is mapped.

Fixes: 97f234f15 ("lib: sbi: Introduce the SBI debug triggers extension support")
Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
lib/sbi/sbi_dbtr.c

index 019e702ca213f16caab34397279423ae570ce34f..7142fedb5a80f65555fc75350ac22ab36f336bd9 100644 (file)
@@ -129,7 +129,7 @@ static inline struct sbi_dbtr_trigger *sbi_alloc_trigger(void)
 
        for (i = 0; i < hart_state->total_trigs; i++) {
                f_trig = INDEX_TO_TRIGGER(i);
-               if (f_trig->state & RV_DBTR_BIT(TS, MAPPED))
+               if (f_trig->state & RV_DBTR_BIT_MASK(TS, MAPPED))
                        continue;
                hart_state->available_trigs--;
                break;