diff mbox series

[1/3] lib: sbi: Refactor sbi_scratch_last_hartindex as a function

Message ID 20230924155745.1753120-2-wxjstz@126.com
State Not Applicable
Headers show
Series [1/3] lib: sbi: Refactor sbi_scratch_last_hartindex as a function | expand

Commit Message

Xiang W Sept. 24, 2023, 3:57 p.m. UTC
Refactor sbi_scratch_last_hartindex as a function. This prevents the
last_hartindex_having_scratch variable from being corrupted elsewhere

Signed-off-by: Xiang W <wxjstz@126.com>
---
 include/sbi/sbi_scratch.h | 5 +----
 lib/sbi/sbi_scratch.c     | 7 ++++++-
 2 files changed, 7 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h
index e6a33ba..28f91ac 100644
--- a/include/sbi/sbi_scratch.h
+++ b/include/sbi/sbi_scratch.h
@@ -202,11 +202,8 @@  do {									\
 					= (__type)(__ptr);		\
 } while (0)
 
-/** Last HART index having a sbi_scratch pointer */
-extern u32 last_hartindex_having_scratch;
-
 /** Get last HART index having a sbi_scratch pointer */
-#define sbi_scratch_last_hartindex()	last_hartindex_having_scratch
+u32 sbi_scratch_last_hartindex(void);
 
 /** Check whether a particular HART index is valid or not */
 #define sbi_hartindex_valid(__hartindex) \
diff --git a/lib/sbi/sbi_scratch.c b/lib/sbi/sbi_scratch.c
index ccbbc68..5dab2e6 100644
--- a/lib/sbi/sbi_scratch.c
+++ b/lib/sbi/sbi_scratch.c
@@ -14,13 +14,18 @@ 
 #include <sbi/sbi_scratch.h>
 #include <sbi/sbi_string.h>
 
-u32 last_hartindex_having_scratch = 0;
+static 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 };
 
 static spinlock_t extra_lock = SPIN_LOCK_INITIALIZER;
 static unsigned long extra_offset = SBI_SCRATCH_EXTRA_SPACE_OFFSET;
 
+u32 sbi_scratch_last_hartindex(void)
+{
+	return last_hartindex_having_scratch;
+}
+
 u32 sbi_hartid_to_hartindex(u32 hartid)
 {
 	u32 i;