diff options
Diffstat (limited to 'arch/mips/kernel/setup.c')
-rw-r--r-- | arch/mips/kernel/setup.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index a53f8ec37aac..290dc6a1d7a3 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c | |||
@@ -79,7 +79,7 @@ static struct resource data_resource = { .name = "Kernel data", }; | |||
79 | void __init add_memory_region(phys_t start, phys_t size, long type) | 79 | void __init add_memory_region(phys_t start, phys_t size, long type) |
80 | { | 80 | { |
81 | int x = boot_mem_map.nr_map; | 81 | int x = boot_mem_map.nr_map; |
82 | struct boot_mem_map_entry *prev = boot_mem_map.map + x - 1; | 82 | int i; |
83 | 83 | ||
84 | /* Sanity check */ | 84 | /* Sanity check */ |
85 | if (start + size < start) { | 85 | if (start + size < start) { |
@@ -88,15 +88,29 @@ void __init add_memory_region(phys_t start, phys_t size, long type) | |||
88 | } | 88 | } |
89 | 89 | ||
90 | /* | 90 | /* |
91 | * Try to merge with previous entry if any. This is far less than | 91 | * Try to merge with existing entry, if any. |
92 | * perfect but is sufficient for most real world cases. | ||
93 | */ | 92 | */ |
94 | if (x && prev->addr + prev->size == start && prev->type == type) { | 93 | for (i = 0; i < boot_mem_map.nr_map; i++) { |
95 | prev->size += size; | 94 | struct boot_mem_map_entry *entry = boot_mem_map.map + i; |
95 | unsigned long top; | ||
96 | |||
97 | if (entry->type != type) | ||
98 | continue; | ||
99 | |||
100 | if (start + size < entry->addr) | ||
101 | continue; /* no overlap */ | ||
102 | |||
103 | if (entry->addr + entry->size < start) | ||
104 | continue; /* no overlap */ | ||
105 | |||
106 | top = max(entry->addr + entry->size, start + size); | ||
107 | entry->addr = min(entry->addr, start); | ||
108 | entry->size = top - entry->addr; | ||
109 | |||
96 | return; | 110 | return; |
97 | } | 111 | } |
98 | 112 | ||
99 | if (x == BOOT_MEM_MAP_MAX) { | 113 | if (boot_mem_map.nr_map == BOOT_MEM_MAP_MAX) { |
100 | pr_err("Ooops! Too many entries in the memory map!\n"); | 114 | pr_err("Ooops! Too many entries in the memory map!\n"); |
101 | return; | 115 | return; |
102 | } | 116 | } |