lib: utils/irqchip: Add sanity checks in imsic_get_data() and imsic_get_target_file()

Add extra sanity checks to prevent the caller getting the invalid result from
imsic_get_data() or imsic_get_target_file() when imsic is not initialized
correctly.

Signed-off-by: Cyan Yang <cyan.yang@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Cyan Yang
2024-05-16 16:32:43 +08:00
committed by Anup Patel
parent 96f0a2e3ea
commit 858754a544

View File

@@ -123,6 +123,9 @@ struct imsic_data *imsic_get_data(u32 hartid)
{
struct sbi_scratch *scratch;
if (!imsic_ptr_offset)
return NULL;
scratch = sbi_hartid_to_scratch(hartid);
if (!scratch)
return NULL;
@@ -134,6 +137,9 @@ int imsic_get_target_file(u32 hartid)
{
struct sbi_scratch *scratch;
if (!imsic_file_offset)
return SBI_ENOENT;
scratch = sbi_hartid_to_scratch(hartid);
if (!scratch)
return SBI_ENOENT;