Skip to contentSkip to conversation

lib: sbi: Ensure domidx_to_domain_table is null-terminated

PATCH New Andrew Jones 2 participants 2 messages Jan 30, 2023 – Feb 8, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: sbi: Ensure domidx_to_domain_table is null-terminated

sbi_domain_for_each() requires domidx_to_domain_table[] to be null-terminated. Allocate one extra element which will always be null.

---
 lib/sbi/sbi_domain.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/sbi/sbi_domain.c +5 -1
index 3ab1fbe0b7de..3813f1b2e97d 100644
@@ -17,8 +17,12 @@
 #include <sbi/sbi_scratch.h>
 #include <sbi/sbi_string.h>
 
+/*
+ * We allocate an extra element because sbi_domain_for_each() expects
+ * the array to be null-terminated.
+ */
+struct sbi_domain *domidx_to_domain_table[SBI_DOMAIN_MAX_INDEX + 1] = { 0 };
 struct sbi_domain *hartid_to_domain_table[SBI_HARTMASK_MAX_BITS] = { 0 };
-struct sbi_domain *domidx_to_domain_table[SBI_DOMAIN_MAX_INDEX] = { 0 };
 static u32 domain_count = 0;
 static bool domain_finalized = false;
 
Signature · 1 line
2.39.1
Applied
#1 lore raw

PATCH 1/1 lib: sbi: Ensure domidx_to_domain_table is null-terminated

Quoted 6 lines · Andrew Jones

sbi_domain_for_each() requires domidx_to_domain_table[] to be null-terminated. Allocate one extra element which will always be null.

Looks good to me.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 30 lines
---
 lib/sbi/sbi_domain.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/sbi/sbi_domain.c +5 -2
index 3ab1fbe0b7de..3813f1b2e97d 100644
@@ -17,8 +17,12 @@
 #include <sbi/sbi_scratch.h>
 #include <sbi/sbi_string.h>
 
+/*
+ * We allocate an extra element because sbi_domain_for_each() expects
+ * the array to be null-terminated.
+ */
+struct sbi_domain *domidx_to_domain_table[SBI_DOMAIN_MAX_INDEX + 1] = { 0 };
 struct sbi_domain *hartid_to_domain_table[SBI_HARTMASK_MAX_BITS] = { 0 };
-struct sbi_domain *domidx_to_domain_table[SBI_DOMAIN_MAX_INDEX] = { 0 };
 static u32 domain_count = 0;
 static bool domain_finalized = false;
 
--

2.39.1

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