Skip to content

Commit

Permalink
RISC-V: Do not allocate memblock while iterating reserved memblocks
Browse files Browse the repository at this point in the history
Signed-off-by: Atish Patra <atish.patra@wdc.com>
  • Loading branch information
atishp04 committed Dec 19, 2020
1 parent 2f66d66 commit 6fd60f7
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions arch/riscv/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ static void __init init_resources(void)
{
struct memblock_region *region = NULL;
struct resource *res = NULL;
int ret = 0;
int ret = 0, i = 0;
int num_mem_res;
struct resource *mem_res;

code_res.start = __pa_symbol(_text);
code_res.end = __pa_symbol(_etext) - 1;
Expand All @@ -145,16 +147,17 @@ static void __init init_resources(void)
bss_res.end = __pa_symbol(__bss_stop) - 1;
bss_res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;

num_mem_res = memblock.memory.cnt + memblock.reserved.cnt;
mem_res = memblock_alloc(num_mem_res * sizeof(*mem_res), SMP_CACHE_BYTES);
if (!mem_res)
panic("%s: Failed to allocate %zu bytes\n", __func__, num_mem_res * sizeof(*mem_res));
/*
* Start by adding the reserved regions, if they overlap
* with /memory regions, insert_resource later on will take
* care of it.
*/
for_each_reserved_mem_region(region) {
res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
if (!res)
panic("%s: Failed to allocate %zu bytes\n", __func__,
sizeof(struct resource));
res = &mem_res[i++];

res->name = "Reserved";
res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
Expand All @@ -181,11 +184,8 @@ static void __init init_resources(void)

/* Add /memory regions to the resource tree */
for_each_mem_region(region) {
res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
if (!res)
panic("%s: Failed to allocate %zu bytes\n", __func__,
sizeof(struct resource));

res = &mem_res[i++];
if (unlikely(memblock_is_nomap(region))) {
res->name = "Reserved";
res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
Expand Down

0 comments on commit 6fd60f7

Please sign in to comment.