@@ -343,12 +343,19 @@ static int usermem __initdata;
static int __init early_parse_mem(char *p)
{
phys_addr_t start, size;
+ phys_addr_t pa_start, pa_end;
+ u64 idx;
if (!p) {
pr_err("mem parameter is empty, do nothing\n");
return -EINVAL;
}
+ start = 0;
+ size = memparse(p, &p);
+ if (*p == '@')
+ start = memparse(p + 1, &p);
+
/*
* If a user specifies memory size, we
* blow away any automatically generated
@@ -356,13 +363,20 @@ static int __init early_parse_mem(char *p)
*/
if (usermem == 0) {
usermem = 1;
+ for_each_mem_range(idx, &pa_start, &pa_end) {
+ if (start >= pa_start && size <= pa_end - pa_start)
+ break;
+
+ if (idx < memblock.memory.cnt)
+ continue;
+
+ usermem = -1;
+ pr_err("mem parameter is invalid, do nothing\n");
+ return -EINVAL;
+ }
memblock_remove(memblock_start_of_DRAM(),
memblock_end_of_DRAM() - memblock_start_of_DRAM());
}
- start = 0;
- size = memparse(p, &p);
- if (*p == '@')
- start = memparse(p + 1, &p);
memblock_add(start, size);
@@ -638,7 +652,7 @@ static void __init arch_mem_init(char **cmdline_p)
parse_early_param();
- if (usermem)
+ if (usermem == 1)
pr_info("User-defined physical RAM map overwrite\n");
check_kernel_sections_mem();
In the current code, the users usually need to make sure the value of mem parameter is correct, but it is better to do some check to avoid potential boot hangs. This commit checks whether the first mem parameter is invalid, if yes, return -EINVAL before call memblock_remove() and memblock_add(). Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> --- arch/mips/kernel/setup.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)