From 73c19e69f3000351dc30d272a17dffa694e9b6bf Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 3 Jan 2020 14:55:04 +0530 Subject: [PATCH] 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 Reviewed-by: Atish Patra --- lib/sbi/sbi_scratch.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/sbi/sbi_scratch.c b/lib/sbi/sbi_scratch.c index 0a615a2c..95ee2f2d 100644 --- a/lib/sbi/sbi_scratch.c +++ b/lib/sbi/sbi_scratch.c @@ -8,14 +8,21 @@ */ #include +#include +#include #include +#include 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; }