@@ -127,7 +127,9 @@ static void __init init_resources(void)
127127{
128128 struct memblock_region * region = NULL ;
129129 struct resource * res = NULL ;
130- int ret = 0 ;
130+ struct resource * mem_res = NULL ;
131+ size_t mem_res_sz = 0 ;
132+ int ret = 0 , i = 0 ;
131133
132134 code_res .start = __pa_symbol (_text );
133135 code_res .end = __pa_symbol (_etext ) - 1 ;
@@ -145,16 +147,17 @@ static void __init init_resources(void)
145147 bss_res .end = __pa_symbol (__bss_stop ) - 1 ;
146148 bss_res .flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY ;
147149
150+ mem_res_sz = (memblock .memory .cnt + memblock .reserved .cnt ) * sizeof (* mem_res );
151+ mem_res = memblock_alloc (mem_res_sz , SMP_CACHE_BYTES );
152+ if (!mem_res )
153+ panic ("%s: Failed to allocate %zu bytes\n" , __func__ , mem_res_sz );
148154 /*
149155 * Start by adding the reserved regions, if they overlap
150156 * with /memory regions, insert_resource later on will take
151157 * care of it.
152158 */
153159 for_each_reserved_mem_region (region ) {
154- res = memblock_alloc (sizeof (struct resource ), SMP_CACHE_BYTES );
155- if (!res )
156- panic ("%s: Failed to allocate %zu bytes\n" , __func__ ,
157- sizeof (struct resource ));
160+ res = & mem_res [i ++ ];
158161
159162 res -> name = "Reserved" ;
160163 res -> flags = IORESOURCE_MEM | IORESOURCE_BUSY ;
@@ -171,8 +174,10 @@ static void __init init_resources(void)
171174 * Ignore any other reserved regions within
172175 * system memory.
173176 */
174- if (memblock_is_memory (res -> start ))
177+ if (memblock_is_memory (res -> start )) {
178+ memblock_free ((phys_addr_t ) res , sizeof (struct resource ));
175179 continue ;
180+ }
176181
177182 ret = add_resource (& iomem_resource , res );
178183 if (ret < 0 )
@@ -181,10 +186,7 @@ static void __init init_resources(void)
181186
182187 /* Add /memory regions to the resource tree */
183188 for_each_mem_region (region ) {
184- res = memblock_alloc (sizeof (struct resource ), SMP_CACHE_BYTES );
185- if (!res )
186- panic ("%s: Failed to allocate %zu bytes\n" , __func__ ,
187- sizeof (struct resource ));
189+ res = & mem_res [i ++ ];
188190
189191 if (unlikely (memblock_is_nomap (region ))) {
190192 res -> name = "Reserved" ;
@@ -205,9 +207,9 @@ static void __init init_resources(void)
205207 return ;
206208
207209 error :
208- memblock_free ((phys_addr_t ) res , sizeof (struct resource ));
209210 /* Better an empty resource tree than an inconsistent one */
210211 release_child_resources (& iomem_resource );
212+ memblock_free ((phys_addr_t ) mem_res , mem_res_sz );
211213}
212214
213215
0 commit comments