summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/sbi/sbi_scratch.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/sbi/sbi_scratch.c b/lib/sbi/sbi_scratch.c
index ccbbc68e..5a9e935b 100644
--- a/lib/sbi/sbi_scratch.c
+++ b/lib/sbi/sbi_scratch.c
@@ -15,8 +15,8 @@
#include <sbi/sbi_string.h>
u32 last_hartindex_having_scratch = 0;
-u32 hartindex_to_hartid_table[SBI_HARTMASK_MAX_BITS + 1] = { -1U };
-struct sbi_scratch *hartindex_to_scratch_table[SBI_HARTMASK_MAX_BITS + 1] = { 0 };
+u32 hartindex_to_hartid_table[SBI_HARTMASK_MAX_BITS] = { -1U };
+struct sbi_scratch *hartindex_to_scratch_table[SBI_HARTMASK_MAX_BITS] = { 0 };
static spinlock_t extra_lock = SPIN_LOCK_INITIALIZER;
static unsigned long extra_offset = SBI_SCRATCH_EXTRA_SPACE_OFFSET;
@@ -36,17 +36,21 @@ typedef struct sbi_scratch *(*hartid2scratch)(ulong hartid, ulong hartindex);
int sbi_scratch_init(struct sbi_scratch *scratch)
{
- u32 i, h;
+ u32 i, h, hart_count;
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
- for (i = 0; i < plat->hart_count; i++) {
+ hart_count = plat->hart_count;
+ if (hart_count > SBI_HARTMASK_MAX_BITS)
+ hart_count = SBI_HARTMASK_MAX_BITS;
+
+ for (i = 0; i < hart_count; i++) {
h = (plat->hart_index2id) ? plat->hart_index2id[i] : i;
hartindex_to_hartid_table[i] = h;
hartindex_to_scratch_table[i] =
((hartid2scratch)scratch->hartid_to_scratch)(h, i);
}
- last_hartindex_having_scratch = plat->hart_count - 1;
+ last_hartindex_having_scratch = hart_count - 1;
return 0;
}