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

Cyan Yang cyan.yang at sifive.com
Thu May 16 01:32:43 PDT 2024


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 at sifive.com>
---
 lib/utils/irqchip/imsic.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/utils/irqchip/imsic.c b/lib/utils/irqchip/imsic.c
index 02e3a33..7d6993e 100644
--- a/lib/utils/irqchip/imsic.c
+++ b/lib/utils/irqchip/imsic.c
@@ -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;
-- 
2.39.3 (Apple Git-146)




More information about the opensbi mailing list