Skip to content

Commit e8717d1

Browse files
clementlegeravpatel
authored andcommitted
lib: sbi: fwft: check feature value to be exactly 1 or 0
As stated by the spec and pointed out by Andrew Jones, the value passed for MISALIGNED_EXC_DELEG and PTE_AD_HW_UPDATING should be either 0 or 1. Add check for these values and return SBI_EINVAL if not. Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
1 parent ecef14d commit e8717d1

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

lib/sbi/sbi_fwft.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,12 @@ static int fwft_misaligned_delegation_supported(struct fwft_config *conf)
8484
static int fwft_set_misaligned_delegation(struct fwft_config *conf,
8585
unsigned long value)
8686
{
87-
if (value)
87+
if (value == 1)
8888
csr_set(CSR_MEDELEG, MIS_DELEG);
89-
else
89+
else if (value == 0)
9090
csr_clear(CSR_MEDELEG, MIS_DELEG);
91+
else
92+
return SBI_EINVAL;
9193

9294
return SBI_OK;
9395
}
@@ -111,18 +113,20 @@ static int fwft_adue_supported(struct fwft_config *conf)
111113

112114
static int fwft_set_adue(struct fwft_config *conf, unsigned long value)
113115
{
114-
if (value)
116+
if (value == 1)
115117
#if __riscv_xlen == 32
116118
csr_set(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
117119
#else
118120
csr_set(CSR_MENVCFG, ENVCFG_ADUE);
119121
#endif
120-
else
122+
else if (value == 0)
121123
#if __riscv_xlen == 32
122124
csr_clear(CSR_MENVCFGH, ENVCFG_ADUE >> 32);
123125
#else
124126
csr_clear(CSR_MENVCFG, ENVCFG_ADUE);
125127
#endif
128+
else
129+
return SBI_EINVAL;
126130

127131
return SBI_OK;
128132
}

0 commit comments

Comments
 (0)