aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@wdc.com>2020-01-03 14:55:04 +0530
committerAnup Patel <anup.patel@wdc.com>2020-01-07 12:11:41 +0530
commit73c19e69f3000351dc30d272a17dffa694e9b6bf (patch)
tree394f10ea28d4d6f233f0da9b9af595d59c407e7d
parent15ed1e74526d85f94c2cda338c572e36e249c803 (diff)
lib: zero-out memory allocated using sbi_scratch_alloc_offset()
We should zero-out memory allocated from extra scratch space using sbi_scratch_alloc_offset() API hence this patch. This will not impact performance because we mostly allocate from extra scratch space only at cold boot time. Signed-off-by: Anup Patel <anup@brainfault.org> Reviewed-by: Atish Patra <atish.patra@wdc.com>
-rw-r--r--lib/sbi/sbi_scratch.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/sbi/sbi_scratch.c b/lib/sbi/sbi_scratch.c
index 0a615a2..95ee2f2 100644
--- a/lib/sbi/sbi_scratch.c
+++ b/lib/sbi/sbi_scratch.c
@@ -8,14 +8,21 @@
*/
#include <sbi/riscv_locks.h>
+#include <sbi/sbi_hart.h>
+#include <sbi/sbi_platform.h>
#include <sbi/sbi_scratch.h>
+#include <sbi/sbi_string.h>
static spinlock_t extra_lock = SPIN_LOCK_INITIALIZER;
static unsigned long extra_offset = SBI_SCRATCH_EXTRA_SPACE_OFFSET;
unsigned long sbi_scratch_alloc_offset(unsigned long size, const char *owner)
{
+ u32 i;
+ void *ptr;
unsigned long ret = 0;
+ struct sbi_scratch *scratch, *rscratch;
+ const struct sbi_platform *plat;
/*
* We have a simple brain-dead allocator which never expects
@@ -43,6 +50,16 @@ unsigned long sbi_scratch_alloc_offset(unsigned long size, const char *owner)
done:
spin_unlock(&extra_lock);
+ if (ret) {
+ scratch = sbi_scratch_thishart_ptr();
+ plat = sbi_platform_ptr(scratch);
+ for (i = 0; i < sbi_platform_hart_count(plat); i++) {
+ rscratch = sbi_hart_id_to_scratch(scratch, i);
+ ptr = sbi_scratch_offset_ptr(rscratch, ret);
+ sbi_memset(ptr, 0, size);
+ }
+ }
+
return ret;
}