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 <merle@hardenedlinux.org>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:
Xiang Wang
2020-03-24 10:11:48 +00:00
committed by Anup Patel
parent 4c374511fd
commit 4d93586bfa

View File

@@ -285,7 +285,7 @@ void __noreturn sbi_init(struct sbi_scratch *scratch)
sbi_platform_hart_invalid(plat, hartid)) sbi_platform_hart_invalid(plat, hartid))
sbi_hart_hang(); sbi_hart_hang();
if (atomic_add_return(&coldboot_lottery, 1) == 1) if (arch_atomic_xchg(&coldboot_lottery, 1) == 0)
coldboot = TRUE; coldboot = TRUE;
if (coldboot) if (coldboot)