From 357273ae377ce27df04552819019aba143129590 Mon Sep 17 00:00:00 2001 From: Ronald G Minnich Date: Fri, 5 Apr 2024 16:13:43 -0700 Subject: [PATCH] create a size variable for the sbi_hart_ext On some platforms, e.g. coreboot, opensbi fails as the loop in fdt_parse_isa_one_hart is for SBI_HART_EXT_MAX (32) items, and the array is only 15 at present. Create a variable, sbi_hart_ext_size, which can be used in for loops and other conditionals. Signed-off-by: Ronald G Minnich --- include/sbi/sbi_hart.h | 1 + lib/sbi/sbi_hart.c | 2 ++ lib/utils/fdt/fdt_helper.c | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index cc78eec6f6..da58ccc915 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -74,6 +74,7 @@ struct sbi_hart_ext_data { }; extern const struct sbi_hart_ext_data sbi_hart_ext[]; +extern const int sbi_hart_ext_size; /* * Smepmp enforces access boundaries between M-mode and diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 3d1369441c..6a2c6b70a4 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -668,6 +668,8 @@ const struct sbi_hart_ext_data sbi_hart_ext[] = { __SBI_HART_EXT_DATA(smcdeleg, SBI_HART_EXT_SMCDELEG), }; +const int sbi_hart_ext_size = sizeof(sbi_hart_ext) / sizeof(sbi_hart_ext[0]); + /** * Get the hart extensions in string format * diff --git a/lib/utils/fdt/fdt_helper.c b/lib/utils/fdt/fdt_helper.c index a0e93b9226..c66160040f 100644 --- a/lib/utils/fdt/fdt_helper.c +++ b/lib/utils/fdt/fdt_helper.c @@ -401,7 +401,7 @@ static int fdt_parse_isa_one_hart(const char *isa, unsigned long *extensions) continue; \ } - for (j = 0; j < SBI_HART_EXT_MAX; j++) { + for (j = 0; j < sbi_hart_ext_size; j++) { set_multi_letter_ext(sbi_hart_ext[j].name, sbi_hart_ext[j].id); }