Skip to contentSkip to conversation

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

PATCH New Cyan Yang 2 participants 3 messages May 16, 2024 – May 23, 2024

lore
Share & tools
lore

Cyan Yang

author
#0 lore raw

PATCH 1/1 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.

---
 lib/utils/irqchip/imsic.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/utils/irqchip/imsic.c +6 -0
index 02e3a33..7d6993e 100644
@@ -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;
Signature · 1 line
2.39.3 (Apple Git-146)
#1 lore raw

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

Quoted 6 lines · On Thu, May 16, 2024 at 2:03?PM Cyan Yang <[email protected]> wrote:

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.

LGTM.

Regards,
Anup

Quoted 36 lines
---
 lib/utils/irqchip/imsic.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/utils/irqchip/imsic.c +6 -1
index 02e3a33..7d6993e 100644
@@ -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)

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Applied
#2 lore raw

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

In reply to Cyan Yang
Quoted 6 lines · On Thu, May 16, 2024 at 2:03?PM Cyan Yang <[email protected]> wrote:

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.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 36 lines
---
 lib/utils/irqchip/imsic.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/utils/irqchip/imsic.c +6 -1
index 02e3a33..7d6993e 100644
@@ -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)

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi