提交 bb0b6f39 编写于 作者: M Max Filippov 提交者: Michael Tokarev

hw/xtensa: sim: use g_string/g_new

Replace malloc/free/sprintf with g_string/g_string_printf/g_string_free.
Replace g_malloc with g_new when allocating the MemoryRegion to get more
type safety.
Suggested-by: NAlex Bennée <alex.bennee@linaro.org>
Signed-off-by: NMax Filippov <jcmvbkbc@gmail.com>
Reviewed-by: NPhilippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: NMichael Tokarev <mjt@tls.msk.ru>
上级 95e9a242
......@@ -41,21 +41,21 @@ static void xtensa_create_memory_regions(const XtensaMemory *memory,
const char *name)
{
unsigned i;
char *num_name = malloc(strlen(name) + sizeof(i) * 3 + 1);
GString *num_name = g_string_new(NULL);
for (i = 0; i < memory->num; ++i) {
MemoryRegion *m;
sprintf(num_name, "%s%u", name, i);
m = g_malloc(sizeof(*m));
memory_region_init_ram(m, NULL, num_name,
g_string_printf(num_name, "%s%u", name, i);
m = g_new(MemoryRegion, 1);
memory_region_init_ram(m, NULL, num_name->str,
memory->location[i].size,
&error_fatal);
vmstate_register_ram_global(m);
memory_region_add_subregion(get_system_memory(),
memory->location[i].addr, m);
}
free(num_name);
g_string_free(num_name, true);
}
static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册