sh: fix memory corruption of unflattened device tree
authorRich Felker <dalias@libc.org>
Mon, 31 Jul 2017 05:27:50 +0000 (01:27 -0400)
committerRich Felker <dalias@libc.org>
Thu, 12 Apr 2018 23:47:51 +0000 (19:47 -0400)
unflatten_device_tree() makes use of memblock allocation, and
therefore must be called before paging_init() migrates the memblock
allocation data to the bootmem framework. Otherwise the record of the
allocation for the expanded device tree will be lost, and will
eventually be clobbered when allocated for another use.

Signed-off-by: Rich Felker <dalias@libc.org>
arch/sh/boards/of-generic.c
arch/sh/kernel/setup.c

index 4feb7c86f4acfb56e18561ffdcd24188a5ba4ee8..46b2481eec9034e1cbb5adbdf4f37cb34d085452 100644 (file)
@@ -126,12 +126,6 @@ static void __init sh_of_setup(char **cmdline_p)
 {
        struct device_node *root;
 
-#ifdef CONFIG_USE_BUILTIN_DTB
-       unflatten_and_copy_device_tree();
-#else
-       unflatten_device_tree();
-#endif
-
        board_time_init = sh_of_time_init;
 
        sh_mv.mv_name = "Unknown SH model";
index b95c411d03337e4b44edaa895437e253eeeed948..d34e998b809f3461be121935359ba26e5613b8c7 100644 (file)
@@ -330,6 +330,14 @@ void __init setup_arch(char **cmdline_p)
        /* Let earlyprintk output early console messages */
        early_platform_driver_probe("earlyprintk", 1, 1);
 
+#ifdef CONFIG_OF_FLATTREE
+#ifdef CONFIG_USE_BUILTIN_DTB
+       unflatten_and_copy_device_tree();
+#else
+       unflatten_device_tree();
+#endif
+#endif
+
        paging_init();
 
 #ifdef CONFIG_DUMMY_CONSOLE