qemu-e2k/hw/remote/memory.c
Zenghui Yu d90226808b multi-process: Initialize variables declared with g_auto*
Quote docs/devel/style.rst (section "Automatic memory deallocation"):

* Variables declared with g_auto* MUST always be initialized,
  otherwise the cleanup function will use uninitialized stack memory

Initialize @name properly to get rid of the compilation error (using
gcc-7.3.0 on CentOS):

../hw/remote/proxy.c: In function 'pci_proxy_dev_realize':
/usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: 'name' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   g_free (*pp);
   ^~~~~~~~~~~~
../hw/remote/proxy.c:350:30: note: 'name' was declared here
             g_autofree char *name;
                              ^~~~

Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
Reviewed-by: Jagannathan Raman <jag.raman@oracle.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Miroslav Rezanina <mrezanin@redhat.com>
Message-id: 20210312112143.1369-1-yuzenghui@huawei.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2021-05-21 15:43:57 +01:00

64 lines
1.7 KiB
C

/*
* Memory manager for remote device
*
* Copyright © 2018, 2021 Oracle and/or its affiliates.
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*
*/
#include "qemu/osdep.h"
#include "qemu-common.h"
#include "hw/remote/memory.h"
#include "exec/ram_addr.h"
#include "qapi/error.h"
static void remote_sysmem_reset(void)
{
MemoryRegion *sysmem, *subregion, *next;
sysmem = get_system_memory();
QTAILQ_FOREACH_SAFE(subregion, &sysmem->subregions, subregions_link, next) {
if (subregion->ram) {
memory_region_del_subregion(sysmem, subregion);
object_unparent(OBJECT(subregion));
}
}
}
void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp)
{
ERRP_GUARD();
SyncSysmemMsg *sysmem_info = &msg->data.sync_sysmem;
MemoryRegion *sysmem, *subregion;
static unsigned int suffix;
int region;
sysmem = get_system_memory();
remote_sysmem_reset();
for (region = 0; region < msg->num_fds; region++, suffix++) {
g_autofree char *name = g_strdup_printf("remote-mem-%u", suffix);
subregion = g_new(MemoryRegion, 1);
memory_region_init_ram_from_fd(subregion, NULL,
name, sysmem_info->sizes[region],
true, msg->fds[region],
sysmem_info->offsets[region],
errp);
if (*errp) {
g_free(subregion);
remote_sysmem_reset();
return;
}
memory_region_add_subregion(sysmem, sysmem_info->gpas[region],
subregion);
}
}