aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2021-01-13 16:10:13 -0600
committerMarkus Armbruster <armbru@redhat.com>2021-01-28 08:08:45 +0100
commit95b3a8c8a82a34ca874ac0d4a9bbbdb38034acf3 (patch)
tree76d842228434aa8ac1dc10f8fcc4bfc5cce422d5 /hw
parentc3033fd372fdaf5b89190136a74b3d78880b85d6 (diff)
qapi: More complex uses of QAPI_LIST_APPEND
These cases require a bit more thought to review; in each case, the code was appending to a list, but not with a FOOList **tail variable. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20210113221013.390592-6-eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Flawed change to qmp_guest_network_get_interfaces() dropped] Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/core/machine-qmp-cmds.c93
-rw-r--r--hw/mem/memory-device.c12
-rw-r--r--hw/pci/pci.c60
3 files changed, 60 insertions, 105 deletions
diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index 156223a344..44e979e503 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -28,11 +28,11 @@ CpuInfoList *qmp_query_cpus(Error **errp)
{
MachineState *ms = MACHINE(qdev_get_machine());
MachineClass *mc = MACHINE_GET_CLASS(ms);
- CpuInfoList *head = NULL, *cur_item = NULL;
+ CpuInfoList *head = NULL, **tail = &head;
CPUState *cpu;
CPU_FOREACH(cpu) {
- CpuInfoList *info;
+ CpuInfo *value;
#if defined(TARGET_I386)
X86CPU *x86_cpu = X86_CPU(cpu);
CPUX86State *env = &x86_cpu->env;
@@ -58,53 +58,46 @@ CpuInfoList *qmp_query_cpus(Error **errp)
cpu_synchronize_state(cpu);
- info = g_malloc0(sizeof(*info));
- info->value = g_malloc0(sizeof(*info->value));
- info->value->CPU = cpu->cpu_index;
- info->value->current = (cpu == first_cpu);
- info->value->halted = cpu->halted;
- info->value->qom_path = object_get_canonical_path(OBJECT(cpu));
- info->value->thread_id = cpu->thread_id;
+ value = g_malloc0(sizeof(*value));
+ value->CPU = cpu->cpu_index;
+ value->current = (cpu == first_cpu);
+ value->halted = cpu->halted;
+ value->qom_path = object_get_canonical_path(OBJECT(cpu));
+ value->thread_id = cpu->thread_id;
#if defined(TARGET_I386)
- info->value->arch = CPU_INFO_ARCH_X86;
- info->value->u.x86.pc = env->eip + env->segs[R_CS].base;
+ value->arch = CPU_INFO_ARCH_X86;
+ value->u.x86.pc = env->eip + env->segs[R_CS].base;
#elif defined(TARGET_PPC)
- info->value->arch = CPU_INFO_ARCH_PPC;
- info->value->u.ppc.nip = env->nip;
+ value->arch = CPU_INFO_ARCH_PPC;
+ value->u.ppc.nip = env->nip;
#elif defined(TARGET_SPARC)
- info->value->arch = CPU_INFO_ARCH_SPARC;
- info->value->u.q_sparc.pc = env->pc;
- info->value->u.q_sparc.npc = env->npc;
+ value->arch = CPU_INFO_ARCH_SPARC;
+ value->u.q_sparc.pc = env->pc;
+ value->u.q_sparc.npc = env->npc;
#elif defined(TARGET_MIPS)
- info->value->arch = CPU_INFO_ARCH_MIPS;
- info->value->u.q_mips.PC = env->active_tc.PC;
+ value->arch = CPU_INFO_ARCH_MIPS;
+ value->u.q_mips.PC = env->active_tc.PC;
#elif defined(TARGET_TRICORE)
- info->value->arch = CPU_INFO_ARCH_TRICORE;
- info->value->u.tricore.PC = env->PC;
+ value->arch = CPU_INFO_ARCH_TRICORE;
+ value->u.tricore.PC = env->PC;
#elif defined(TARGET_S390X)
- info->value->arch = CPU_INFO_ARCH_S390;
- info->value->u.s390.cpu_state = env->cpu_state;
+ value->arch = CPU_INFO_ARCH_S390;
+ value->u.s390.cpu_state = env->cpu_state;
#elif defined(TARGET_RISCV)
- info->value->arch = CPU_INFO_ARCH_RISCV;
- info->value->u.riscv.pc = env->pc;
+ value->arch = CPU_INFO_ARCH_RISCV;
+ value->u.riscv.pc = env->pc;
#else
- info->value->arch = CPU_INFO_ARCH_OTHER;
+ value->arch = CPU_INFO_ARCH_OTHER;
#endif
- info->value->has_props = !!mc->cpu_index_to_instance_props;
- if (info->value->has_props) {
+ value->has_props = !!mc->cpu_index_to_instance_props;
+ if (value->has_props) {
CpuInstanceProperties *props;
props = g_malloc0(sizeof(*props));
*props = mc->cpu_index_to_instance_props(ms, cpu->cpu_index);
- info->value->props = props;
+ value->props = props;
}
- /* XXX: waiting for the qapi to support GSList */
- if (!cur_item) {
- head = cur_item = info;
- } else {
- cur_item->next = info;
- cur_item = info;
- }
+ QAPI_LIST_APPEND(tail, value);
}
return head;
@@ -170,39 +163,33 @@ CpuInfoFastList *qmp_query_cpus_fast(Error **errp)
{
MachineState *ms = MACHINE(qdev_get_machine());
MachineClass *mc = MACHINE_GET_CLASS(ms);
- CpuInfoFastList *head = NULL, *cur_item = NULL;
+ CpuInfoFastList *head = NULL, **tail = &head;
SysEmuTarget target = qapi_enum_parse(&SysEmuTarget_lookup, TARGET_NAME,
-1, &error_abort);
CPUState *cpu;
CPU_FOREACH(cpu) {
- CpuInfoFastList *info = g_malloc0(sizeof(*info));
- info->value = g_malloc0(sizeof(*info->value));
+ CpuInfoFast *value = g_malloc0(sizeof(*value));
- info->value->cpu_index = cpu->cpu_index;
- info->value->qom_path = object_get_canonical_path(OBJECT(cpu));
- info->value->thread_id = cpu->thread_id;
+ value->cpu_index = cpu->cpu_index;
+ value->qom_path = object_get_canonical_path(OBJECT(cpu));
+ value->thread_id = cpu->thread_id;
- info->value->has_props = !!mc->cpu_index_to_instance_props;
- if (info->value->has_props) {
+ value->has_props = !!mc->cpu_index_to_instance_props;
+ if (value->has_props) {
CpuInstanceProperties *props;
props = g_malloc0(sizeof(*props));
*props = mc->cpu_index_to_instance_props(ms, cpu->cpu_index);
- info->value->props = props;
+ value->props = props;
}
- info->value->arch = sysemu_target_to_cpuinfo_arch(target);
- info->value->target = target;
+ value->arch = sysemu_target_to_cpuinfo_arch(target);
+ value->target = target;
if (target == SYS_EMU_TARGET_S390X) {
- cpustate_to_cpuinfo_s390(&info->value->u.s390x, cpu);
+ cpustate_to_cpuinfo_s390(&value->u.s390x, cpu);
}
- if (!cur_item) {
- head = cur_item = info;
- } else {
- cur_item->next = info;
- cur_item = info;
- }
+ QAPI_LIST_APPEND(tail, value);
}
return head;
diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index cf0627fd01..d9f8301711 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -199,7 +199,7 @@ out:
MemoryDeviceInfoList *qmp_memory_device_list(void)
{
GSList *devices = NULL, *item;
- MemoryDeviceInfoList *list = NULL, *prev = NULL;
+ MemoryDeviceInfoList *list = NULL, **tail = &list;
object_child_foreach(qdev_get_machine(), memory_device_build_list,
&devices);
@@ -207,19 +207,11 @@ MemoryDeviceInfoList *qmp_memory_device_list(void)
for (item = devices; item; item = g_slist_next(item)) {
const MemoryDeviceState *md = MEMORY_DEVICE(item->data);
const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(item->data);
- MemoryDeviceInfoList *elem = g_new0(MemoryDeviceInfoList, 1);
MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1);
mdc->fill_device_info(md, info);
- elem->value = info;
- elem->next = NULL;
- if (prev) {
- prev->next = elem;
- } else {
- list = elem;
- }
- prev = elem;
+ QAPI_LIST_APPEND(tail, info);
}
g_slist_free(devices);
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index a6b0c5602e..512e9042ff 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1683,41 +1683,34 @@ static PciDeviceInfoList *qmp_query_pci_devices(PCIBus *bus, int bus_num);
static PciMemoryRegionList *qmp_query_pci_regions(const PCIDevice *dev)
{
- PciMemoryRegionList *head = NULL, *cur_item = NULL;
+ PciMemoryRegionList *head = NULL, **tail = &head;
int i;
for (i = 0; i < PCI_NUM_REGIONS; i++) {
const PCIIORegion *r = &dev->io_regions[i];
- PciMemoryRegionList *region;
+ PciMemoryRegion *region;
if (!r->size) {
continue;
}
region = g_malloc0(sizeof(*region));
- region->value = g_malloc0(sizeof(*region->value));
if (r->type & PCI_BASE_ADDRESS_SPACE_IO) {
- region->value->type = g_strdup("io");
+ region->type = g_strdup("io");
} else {
- region->value->type = g_strdup("memory");
- region->value->has_prefetch = true;
- region->value->prefetch = !!(r->type & PCI_BASE_ADDRESS_MEM_PREFETCH);
- region->value->has_mem_type_64 = true;
- region->value->mem_type_64 = !!(r->type & PCI_BASE_ADDRESS_MEM_TYPE_64);
+ region->type = g_strdup("memory");
+ region->has_prefetch = true;
+ region->prefetch = !!(r->type & PCI_BASE_ADDRESS_MEM_PREFETCH);
+ region->has_mem_type_64 = true;
+ region->mem_type_64 = !!(r->type & PCI_BASE_ADDRESS_MEM_TYPE_64);
}
- region->value->bar = i;
- region->value->address = r->addr;
- region->value->size = r->size;
+ region->bar = i;
+ region->address = r->addr;
+ region->size = r->size;
- /* XXX: waiting for the qapi to support GSList */
- if (!cur_item) {
- head = cur_item = region;
- } else {
- cur_item->next = region;
- cur_item = region;
- }
+ QAPI_LIST_APPEND(tail, region);
}
return head;
@@ -1814,23 +1807,14 @@ static PciDeviceInfo *qmp_query_pci_device(PCIDevice *dev, PCIBus *bus,
static PciDeviceInfoList *qmp_query_pci_devices(PCIBus *bus, int bus_num)
{
- PciDeviceInfoList *info, *head = NULL, *cur_item = NULL;
+ PciDeviceInfoList *head = NULL, **tail = &head;
PCIDevice *dev;
int devfn;
for (devfn = 0; devfn < ARRAY_SIZE(bus->devices); devfn++) {
dev = bus->devices[devfn];
if (dev) {
- info = g_malloc0(sizeof(*info));
- info->value = qmp_query_pci_device(dev, bus, bus_num);
-
- /* XXX: waiting for the qapi to support GSList */
- if (!cur_item) {
- head = cur_item = info;
- } else {
- cur_item->next = info;
- cur_item = info;
- }
+ QAPI_LIST_APPEND(tail, qmp_query_pci_device(dev, bus, bus_num));
}
}
@@ -1853,21 +1837,13 @@ static PciInfo *qmp_query_pci_bus(PCIBus *bus, int bus_num)
PciInfoList *qmp_query_pci(Error **errp)
{
- PciInfoList *info, *head = NULL, *cur_item = NULL;
+ PciInfoList *head = NULL, **tail = &head;
PCIHostState *host_bridge;
QLIST_FOREACH(host_bridge, &pci_host_bridges, next) {
- info = g_malloc0(sizeof(*info));
- info->value = qmp_query_pci_bus(host_bridge->bus,
- pci_bus_num(host_bridge->bus));
-
- /* XXX: waiting for the qapi to support GSList */
- if (!cur_item) {
- head = cur_item = info;
- } else {
- cur_item->next = info;
- cur_item = info;
- }
+ QAPI_LIST_APPEND(tail,
+ qmp_query_pci_bus(host_bridge->bus,
+ pci_bus_num(host_bridge->bus)));
}
return head;