aboutsummaryrefslogtreecommitdiff
path: root/qga
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2021-01-13 16:10:12 -0600
committerMarkus Armbruster <armbru@redhat.com>2021-01-28 08:08:45 +0100
commitc3033fd372fdaf5b89190136a74b3d78880b85d6 (patch)
tree6c2464ae3f51b43702c448606acb3a6c21b6b634 /qga
parentdc13f40c6ba291e31d09053815c230ed88c8921f (diff)
downloadqemu-c3033fd372fdaf5b89190136a74b3d78880b85d6.zip
qemu-c3033fd372fdaf5b89190136a74b3d78880b85d6.tar.gz
qemu-c3033fd372fdaf5b89190136a74b3d78880b85d6.tar.bz2
qapi: Use QAPI_LIST_APPEND in trivial cases
The easiest spots to use QAPI_LIST_APPEND are where we already have an obvious pointer to the tail of a list. While at it, consistently use the variable name 'tail' for that purpose. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20210113221013.390592-5-eblake@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'qga')
-rw-r--r--qga/commands-posix.c31
-rw-r--r--qga/commands-win32.c11
2 files changed, 12 insertions, 30 deletions
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index edf785b..f0a23b0 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -2474,18 +2474,17 @@ static void transfer_vcpu(GuestLogicalProcessor *vcpu, bool sys2vcpu,
GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
{
int64_t current;
- GuestLogicalProcessorList *head, **link;
+ GuestLogicalProcessorList *head, **tail;
long sc_max;
Error *local_err = NULL;
current = 0;
head = NULL;
- link = &head;
+ tail = &head;
sc_max = SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err);
while (local_err == NULL && current < sc_max) {
GuestLogicalProcessor *vcpu;
- GuestLogicalProcessorList *entry;
int64_t id = current++;
char *path = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/",
id);
@@ -2495,10 +2494,7 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
vcpu->logical_id = id;
vcpu->has_can_offline = true; /* lolspeak ftw */
transfer_vcpu(vcpu, true, path, &local_err);
- entry = g_malloc0(sizeof *entry);
- entry->value = vcpu;
- *link = entry;
- link = &entry->next;
+ QAPI_LIST_APPEND(tail, vcpu);
}
g_free(path);
}
@@ -2831,13 +2827,13 @@ out1:
GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp)
{
- GuestMemoryBlockList *head, **link;
+ GuestMemoryBlockList *head, **tail;
Error *local_err = NULL;
struct dirent *de;
DIR *dp;
head = NULL;
- link = &head;
+ tail = &head;
dp = opendir("/sys/devices/system/memory/");
if (!dp) {
@@ -2859,7 +2855,6 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp)
*/
while ((de = readdir(dp)) != NULL) {
GuestMemoryBlock *mem_blk;
- GuestMemoryBlockList *entry;
if ((strncmp(de->d_name, "memory", 6) != 0) ||
!(de->d_type & DT_DIR)) {
@@ -2875,11 +2870,7 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp)
break;
}
- entry = g_malloc0(sizeof *entry);
- entry->value = mem_blk;
-
- *link = entry;
- link = &entry->next;
+ QAPI_LIST_APPEND(tail, mem_blk);
}
closedir(dp);
@@ -2899,15 +2890,14 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp)
GuestMemoryBlockResponseList *
qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks, Error **errp)
{
- GuestMemoryBlockResponseList *head, **link;
+ GuestMemoryBlockResponseList *head, **tail;
Error *local_err = NULL;
head = NULL;
- link = &head;
+ tail = &head;
while (mem_blks != NULL) {
GuestMemoryBlockResponse *result;
- GuestMemoryBlockResponseList *entry;
GuestMemoryBlock *current_mem_blk = mem_blks->value;
result = g_malloc0(sizeof(*result));
@@ -2916,11 +2906,8 @@ qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks, Error **errp)
if (local_err) { /* should never happen */
goto err;
}
- entry = g_malloc0(sizeof *entry);
- entry->value = result;
- *link = entry;
- link = &entry->next;
+ QAPI_LIST_APPEND(tail, result);
mem_blks = mem_blks->next;
}
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 684639b..a6cc481 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -1833,7 +1833,7 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
{
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION pslpi, ptr;
DWORD length;
- GuestLogicalProcessorList *head, **link;
+ GuestLogicalProcessorList *head, **tail;
Error *local_err = NULL;
int64_t current;
@@ -1841,7 +1841,7 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
length = 0;
current = 0;
head = NULL;
- link = &head;
+ tail = &head;
if ((GetLogicalProcessorInformation(pslpi, &length) == FALSE) &&
(GetLastError() == ERROR_INSUFFICIENT_BUFFER) &&
@@ -1864,18 +1864,13 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
while (cpu_bits > 0) {
if (!!(cpu_bits & 1)) {
GuestLogicalProcessor *vcpu;
- GuestLogicalProcessorList *entry;
vcpu = g_malloc0(sizeof *vcpu);
vcpu->logical_id = current++;
vcpu->online = true;
vcpu->has_can_offline = true;
- entry = g_malloc0(sizeof *entry);
- entry->value = vcpu;
-
- *link = entry;
- link = &entry->next;
+ QAPI_LIST_APPEND(tail, vcpu);
}
cpu_bits >>= 1;
}