Skip to content

Commit

Permalink
memory: Move assignment to ram_block to memory_region_init_*
Browse files Browse the repository at this point in the history
We don't force "const" qualifiers with pointers in QEMU, but it's still
good to keep a clean function interface. Assigning to mr->ram_block is
in this sense ugly - one initializer mutating its owning object's state.

Move it to memory_region_init_*, where mr->ram_addr is assigned.

Reviewed-by: Gonglei <[email protected]>
Signed-off-by: Fam Zheng <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
Fam Zheng authored and bonzini committed Mar 7, 2016
1 parent 528f46a commit 0a75601
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 0 additions & 1 deletion exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,6 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
error_propagate(errp, local_err);
return NULL;
}
mr->ram_block = new_block;
return new_block;
}

Expand Down
5 changes: 5 additions & 0 deletions memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,7 @@ void memory_region_init_ram(MemoryRegion *mr,
mr->terminates = true;
mr->destructor = memory_region_destructor_ram;
ram_block = qemu_ram_alloc(size, mr, errp);
mr->ram_block = ram_block;
mr->ram_addr = ram_block->offset;
mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
}
Expand All @@ -1298,6 +1299,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,
mr->terminates = true;
mr->destructor = memory_region_destructor_ram;
ram_block = qemu_ram_alloc_resizeable(size, max_size, resized, mr, errp);
mr->ram_block = ram_block;
mr->ram_addr = ram_block->offset;
mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
}
Expand All @@ -1318,6 +1320,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,
mr->terminates = true;
mr->destructor = memory_region_destructor_ram;
ram_block = qemu_ram_alloc_from_file(size, mr, share, path, errp);
mr->ram_block = ram_block;
mr->ram_addr = ram_block->offset;
mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
}
Expand All @@ -1340,6 +1343,7 @@ void memory_region_init_ram_ptr(MemoryRegion *mr,
/* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL. */
assert(ptr != NULL);
ram_block = qemu_ram_alloc_from_ptr(size, ptr, mr, &error_fatal);
mr->ram_block = ram_block;
mr->ram_addr = ram_block->offset;
}

Expand Down Expand Up @@ -1377,6 +1381,7 @@ void memory_region_init_rom_device(MemoryRegion *mr,
mr->rom_device = true;
mr->destructor = memory_region_destructor_rom_device;
ram_block = qemu_ram_alloc(size, mr, errp);
mr->ram_block = ram_block;
mr->ram_addr = ram_block->offset;
}

Expand Down

0 comments on commit 0a75601

Please sign in to comment.