@@ -127,7 +127,9 @@ static void __init init_resources(void)
127
127
{
128
128
struct memblock_region * region = NULL ;
129
129
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 ;
131
133
132
134
code_res .start = __pa_symbol (_text );
133
135
code_res .end = __pa_symbol (_etext ) - 1 ;
@@ -145,16 +147,17 @@ static void __init init_resources(void)
145
147
bss_res .end = __pa_symbol (__bss_stop ) - 1 ;
146
148
bss_res .flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY ;
147
149
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 );
148
154
/*
149
155
* Start by adding the reserved regions, if they overlap
150
156
* with /memory regions, insert_resource later on will take
151
157
* care of it.
152
158
*/
153
159
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 ++ ];
158
161
159
162
res -> name = "Reserved" ;
160
163
res -> flags = IORESOURCE_MEM | IORESOURCE_BUSY ;
@@ -171,8 +174,10 @@ static void __init init_resources(void)
171
174
* Ignore any other reserved regions within
172
175
* system memory.
173
176
*/
174
- if (memblock_is_memory (res -> start ))
177
+ if (memblock_is_memory (res -> start )) {
178
+ memblock_free ((phys_addr_t ) res , sizeof (struct resource ));
175
179
continue ;
180
+ }
176
181
177
182
ret = add_resource (& iomem_resource , res );
178
183
if (ret < 0 )
@@ -181,10 +186,7 @@ static void __init init_resources(void)
181
186
182
187
/* Add /memory regions to the resource tree */
183
188
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 ++ ];
188
190
189
191
if (unlikely (memblock_is_nomap (region ))) {
190
192
res -> name = "Reserved" ;
@@ -205,9 +207,9 @@ static void __init init_resources(void)
205
207
return ;
206
208
207
209
error :
208
- memblock_free ((phys_addr_t ) res , sizeof (struct resource ));
209
210
/* Better an empty resource tree than an inconsistent one */
210
211
release_child_resources (& iomem_resource );
212
+ memblock_free ((phys_addr_t ) mem_res , mem_res_sz );
211
213
}
212
214
213
215
0 commit comments