:: commit 6088015eb34edbc56228f2bbb304fabdc26168eb

Mintsuki <mintsuki@protonmail.com> — 2026-02-07 07:55

parents: 005e2643fc

sys/cpu_riscv: Skip re-init when config unchanged to prevent FDT use-after-free

diff --git a/common/sys/cpu_riscv.c b/common/sys/cpu_riscv.c
index 2f12129f..6802484f 100644
--- a/common/sys/cpu_riscv.c
+++ b/common/sys/cpu_riscv.c
@@ -261,11 +261,16 @@ static void init_riscv_fdt(const void *fdt) {
 }
 
 void init_riscv(const char *config) {
-    while (hart_list != NULL && current_config != config) {
+    if (current_config == config && hart_list != NULL) {
+        return;
+    }
+
+    while (hart_list != NULL) {
         void *cur_hart = hart_list;
         hart_list = hart_list->next;
         pmm_free(cur_hart, sizeof(struct riscv_hart));
     }
+    bsp_hart = NULL;
 
     if (riscv_fdt != NULL) {
         pmm_free(riscv_fdt, fdt_totalsize(riscv_fdt));
tab: 248 wrap: offon