Skip to content

Commit d46869a

Browse files
committed
csky: Add setup_initrd check code
We should give some necessary check for initrd just like other architectures and it seems that setup_initrd() could be a common code for all architectures. Signed-off-by: Guo Ren <[email protected]>
1 parent 4ec575b commit d46869a

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

arch/csky/kernel/setup.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ static void __init csky_memblock_init(void)
4747
signed long size;
4848

4949
memblock_reserve(__pa(_stext), _end - _stext);
50-
#ifdef CONFIG_BLK_DEV_INITRD
51-
memblock_reserve(__pa(initrd_start), initrd_end - initrd_start);
52-
#endif
5350

5451
early_init_fdt_reserve_self();
5552
early_init_fdt_scan_reserved_mem();

arch/csky/mm/init.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/swap.h>
2020
#include <linux/proc_fs.h>
2121
#include <linux/pfn.h>
22+
#include <linux/initrd.h>
2223

2324
#include <asm/setup.h>
2425
#include <asm/cachectl.h>
@@ -36,6 +37,45 @@ unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)]
3637
__page_aligned_bss;
3738
EXPORT_SYMBOL(empty_zero_page);
3839

40+
#ifdef CONFIG_BLK_DEV_INITRD
41+
static void __init setup_initrd(void)
42+
{
43+
unsigned long size;
44+
45+
if (initrd_start >= initrd_end) {
46+
pr_err("initrd not found or empty");
47+
goto disable;
48+
}
49+
50+
if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) {
51+
pr_err("initrd extends beyond end of memory");
52+
goto disable;
53+
}
54+
55+
size = initrd_end - initrd_start;
56+
57+
if (memblock_is_region_reserved(__pa(initrd_start), size)) {
58+
pr_err("INITRD: 0x%08lx+0x%08lx overlaps in-use memory region",
59+
__pa(initrd_start), size);
60+
goto disable;
61+
}
62+
63+
memblock_reserve(__pa(initrd_start), size);
64+
65+
pr_info("Initial ramdisk at: 0x%p (%lu bytes)\n",
66+
(void *)(initrd_start), size);
67+
68+
initrd_below_start_ok = 1;
69+
70+
return;
71+
72+
disable:
73+
initrd_start = initrd_end = 0;
74+
75+
pr_err(" - disabling initrd\n");
76+
}
77+
#endif
78+
3979
void __init mem_init(void)
4080
{
4181
#ifdef CONFIG_HIGHMEM
@@ -47,6 +87,10 @@ void __init mem_init(void)
4787
#endif
4888
high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
4989

90+
#ifdef CONFIG_BLK_DEV_INITRD
91+
setup_initrd();
92+
#endif
93+
5094
memblock_free_all();
5195

5296
#ifdef CONFIG_HIGHMEM

0 commit comments

Comments
 (0)