lib: utils/irqchip: Add sanity checks in imsic_get_data() and imsic_get_target_file()
authorCyan Yang <cyan.yang@sifive.com>
Thu, 16 May 2024 08:32:43 +0000 (16:32 +0800)
committerAnup Patel <anup@brainfault.org>
Thu, 23 May 2024 05:21:29 +0000 (10:51 +0530)
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>
lib/utils/irqchip/imsic.c

index 02e3a334912f033657925af7f09c3eb4b821dbd0..7d6993eabe6b7ecb8c98b2e504b181d704167758 100644 (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;