Make all callers always pass a valid pointer which in turn allows us to
remove return value check from the callers.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/cpu_conf.c | 7 +------
src/conf/cpu_conf.h | 3 ++-
src/cpu/cpu_ppc64.c | 8 ++++++--
src/cpu/cpu_x86.c | 5 +----
src/qemu/qemu_capabilities.c | 20 +++++++++-----------
src/qemu/qemu_migration_cookie.c | 3 +--
src/qemu/qemu_process.c | 3 +--
tests/testutilsqemu.c | 11 +++++------
8 files changed, 26 insertions(+), 34 deletions(-)
diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 3b824e85d2..9f5e8cb848 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -271,12 +271,7 @@ virCPUDefCopyWithoutModel(const virCPUDef *cpu)
virCPUDef *
virCPUDefCopy(const virCPUDef *cpu)
{
- g_autoptr(virCPUDef) copy = NULL;
-
- if (!cpu)
- return NULL;
-
- copy = virCPUDefCopyWithoutModel(cpu);
+ g_autoptr(virCPUDef) copy = virCPUDefCopyWithoutModel(cpu);
virCPUDefCopyModel(copy, cpu, false);
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index 560b597777..82083d668c 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -201,7 +201,8 @@ virCPUDefStealModel(virCPUDef *dst,
bool keepVendor);
virCPUDef *
-virCPUDefCopy(const virCPUDef *cpu);
+virCPUDefCopy(const virCPUDef *cpu)
+ ATTRIBUTE_NONNULL(1);
virCPUDef *
virCPUDefCopyWithoutModel(const virCPUDef *cpu)
diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c
index 30db99cca1..a33e4da9a9 100644
--- a/src/cpu/cpu_ppc64.c
+++ b/src/cpu/cpu_ppc64.c
@@ -406,8 +406,12 @@ ppc64Compute(virCPUDef *host,
size_t i;
/* Ensure existing configurations are handled correctly */
- if (!(cpu = virCPUDefCopy(other)) ||
- virCPUppc64ConvertLegacy(cpu) < 0)
+ if (!other)
+ return VIR_CPU_COMPARE_ERROR;
+
+ cpu = virCPUDefCopy(other);
+
+ if (virCPUppc64ConvertLegacy(cpu) < 0)
return VIR_CPU_COMPARE_ERROR;
if (cpu->arch != VIR_ARCH_NONE) {
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 6560b7a502..a8a537cbb6 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -3206,7 +3206,7 @@ static int
virCPUx86ExpandFeatures(virCPUDef *cpu)
{
virCPUx86Map *map;
- g_autoptr(virCPUDef) expanded = NULL;
+ g_autoptr(virCPUDef) expanded = virCPUDefCopy(cpu);
g_autoptr(virCPUx86Model) model = NULL;
bool host = cpu->type == VIR_CPU_TYPE_HOST;
size_t i;
@@ -3214,9 +3214,6 @@ virCPUx86ExpandFeatures(virCPUDef *cpu)
if (!(map = virCPUx86GetMap()))
return -1;
- if (!(expanded = virCPUDefCopy(cpu)))
- return -1;
-
virCPUDefFreeFeatures(expanded);
if (!(model = x86ModelFind(map, cpu->model))) {
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 9fe6579dfe..94e6e2b914 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1857,17 +1857,14 @@ virQEMUCapsHostCPUDataCopy(virQEMUCapsHostCPUData *dst,
!(dst->info = qemuMonitorCPUModelInfoCopy(src->info)))
return -1;
- if (src->reported &&
- !(dst->reported = virCPUDefCopy(src->reported)))
- return -1;
+ if (src->reported)
+ dst->reported = virCPUDefCopy(src->reported);
- if (src->migratable &&
- !(dst->migratable = virCPUDefCopy(src->migratable)))
- return -1;
+ if (src->migratable)
+ dst->migratable = virCPUDefCopy(src->migratable);
- if (src->full &&
- !(dst->full = virCPUDefCopy(src->full)))
- return -1;
+ if (src->full)
+ dst->full = virCPUDefCopy(src->full);
return 0;
}
@@ -3867,8 +3864,9 @@ virQEMUCapsInitHostCPUModel(virQEMUCaps *qemuCaps,
if (!(fullCPU = virQEMUCapsProbeHostCPU(qemuCaps->arch, NULL)))
goto error;
- if (!(cpuExpanded = virCPUDefCopy(cpu)) ||
- virCPUExpandFeatures(qemuCaps->arch, cpuExpanded) < 0)
+ cpuExpanded = virCPUDefCopy(cpu);
+
+ if (virCPUExpandFeatures(qemuCaps->arch, cpuExpanded) < 0)
goto error;
for (i = 0; i < cpuExpanded->nfeatures; i++) {
diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c
index e151f33e99..26d07d1ad4 100644
--- a/src/qemu/qemu_migration_cookie.c
+++ b/src/qemu/qemu_migration_cookie.c
@@ -542,8 +542,7 @@ qemuMigrationCookieAddCPU(qemuMigrationCookie *mig,
if (mig->cpu)
return 0;
- if (!(mig->cpu = virCPUDefCopy(vm->def->cpu)))
- return -1;
+ mig->cpu = virCPUDefCopy(vm->def->cpu);
if (qemuDomainMakeCPUMigratable(mig->cpu) < 0)
return -1;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index eb1797688c..d0ddf46e98 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4469,8 +4469,7 @@ qemuProcessUpdateLiveGuestCPU(virDomainObj *vm,
!def->cpu->model))
return 0;
- if (!(orig = virCPUDefCopy(def->cpu)))
- return -1;
+ orig = virCPUDefCopy(def->cpu);
if ((rc = virCPUUpdateLive(def->os.arch, def->cpu, enabled, disabled)) < 0)
{
return -1;
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index ef78616062..672316c848 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -577,12 +577,11 @@ int qemuTestDriverInit(virQEMUDriver *driver)
memset(driver, 0, sizeof(*driver));
- if (!(cpuDefault = virCPUDefCopy(&cpuDefaultData)) ||
- !(cpuHaswell = virCPUDefCopy(&cpuHaswellData)) ||
- !(cpuPower8 = virCPUDefCopy(&cpuPower8Data)) ||
- !(cpuPower9 = virCPUDefCopy(&cpuPower9Data)) ||
- !(cpuPower10 = virCPUDefCopy(&cpuPower10Data)))
- return -1;
+ cpuDefault = virCPUDefCopy(&cpuDefaultData);
+ cpuHaswell = virCPUDefCopy(&cpuHaswellData);
+ cpuPower8 = virCPUDefCopy(&cpuPower8Data);
+ cpuPower9 = virCPUDefCopy(&cpuPower9Data);
+ cpuPower10 = virCPUDefCopy(&cpuPower10Data);
if (virMutexInit(&driver->lock) < 0)
return -1;
--
2.39.2