diff mbox

[kvm-unit-tests,2/5] lib/arm/setup: fix and comment init order

Message ID 20161214143954.10452-3-drjones@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrew Jones Dec. 14, 2016, 2:39 p.m. UTC
While reading code I noticed we need to call thread_info_init before
mem_init to be correct. In practice it hasn't mattered because cpu0
is calling mem_init, and it's cpu index is 0, which is what a fresh
first boot would have it be anyway. With reset tests (coming soon)
combined with mmu tests (hopefully coming someday) it could be
problematic though, so let's fix it. Additionally comment the order
to make sure we maintain it. The io_init dependency on mem_init is
because io_init calls init functions that make use of heap allocation.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/setup.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index e52a25abd722..1751c3997c53 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -126,12 +126,17 @@  void setup(const void *fdt)
 	ret = dt_init(&stacktop);
 	assert(ret == 0);
 
-	mem_init(PAGE_ALIGN((unsigned long)&stacktop + fdt_size));
-	io_init();
 	cpu_init();
 
+	/* cpu_init must be called before thread_info_init */
 	thread_info_init(current_thread_info(), 0);
 
+	/* thread_info_init must be called before mem_init */
+	mem_init(PAGE_ALIGN((unsigned long)&stacktop + fdt_size));
+
+	/* mem_init must be called before io_init */
+	io_init();
+
 	ret = dt_get_bootargs(&bootargs);
 	assert(ret == 0);
 	setup_args_progname(bootargs);