diff options
author | Anup Patel <anup.patel@wdc.com> | 2020-03-14 18:55:53 +0530 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2020-03-19 09:11:12 +0530 |
commit | 209134d8f9c6e4ec9a555a7813f7e2c004b5b2d7 (patch) | |
tree | 8c9cda3f1891a2bc9f0e1b33c696f58806799335 /lib/sbi/sbi_hsm.c | |
parent | 3ebfe0ec5d280b0c5ca61b8c5cfe4bc807907630 (diff) |
lib: Handle failure of sbi_hartid_to_scratch() API
The sbi_hartid_to_scratch() API can fail for non-existent HARTs so
all uses of sbi_hartid_to_scratch() API should check return value.
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Diffstat (limited to 'lib/sbi/sbi_hsm.c')
-rw-r--r-- | lib/sbi/sbi_hsm.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c index b403423..1219924 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -61,6 +61,9 @@ int sbi_hsm_hart_get_state(u32 hartid) struct sbi_scratch *scratch; scratch = sbi_hartid_to_scratch(hartid); + if (!scratch) + return SBI_HART_UNKNOWN; + hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset); return atomic_read(&hdata->state); @@ -165,6 +168,9 @@ int sbi_hsm_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot) /* Initialize hart state data for every hart */ for (i = 0; i < hart_count; i++) { rscratch = sbi_hartid_to_scratch(i); + if (!rscratch) + continue; + hdata = sbi_scratch_offset_ptr(rscratch, hart_data_offset); ATOMIC_INIT(&hdata->state, @@ -212,14 +218,17 @@ fail_exit: int sbi_hsm_hart_start(struct sbi_scratch *scratch, u32 hartid, ulong saddr, ulong priv) { + int rc; unsigned long init_count; unsigned int hstate; - int rc; + struct sbi_scratch *rscratch; + struct sbi_hsm_data *hdata; const struct sbi_platform *plat = sbi_platform_ptr(scratch); - struct sbi_scratch *rscratch = sbi_hartid_to_scratch(hartid); - struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(rscratch, - hart_data_offset); + rscratch = sbi_hartid_to_scratch(hartid); + if (!rscratch) + return SBI_EINVAL; + hdata = sbi_scratch_offset_ptr(rscratch, hart_data_offset); if (sbi_platform_hart_disabled(plat, hartid)) return SBI_EINVAL; hstate = arch_atomic_cmpxchg(&hdata->state, SBI_HART_STOPPED, |