From 4d93586bfa9a6875f1f28c5f430b17b650a19207 Mon Sep 17 00:00:00 2001 From: Xiang Wang Date: Tue, 24 Mar 2020 10:11:48 +0000 Subject: [PATCH] lib: prevent coldboot_lottery from overflowing HSM_STOP will trigger multiple executions of sbi_init, atomic_add_return may trigger coldboot_lottery overflow Signed-off-by: Xiang Wang Reviewed-by: Anup Patel --- lib/sbi/sbi_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 90ec64cc..4e1699d5 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -285,7 +285,7 @@ void __noreturn sbi_init(struct sbi_scratch *scratch) sbi_platform_hart_invalid(plat, hartid)) sbi_hart_hang(); - if (atomic_add_return(&coldboot_lottery, 1) == 1) + if (arch_atomic_xchg(&coldboot_lottery, 1) == 0) coldboot = TRUE; if (coldboot)