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_arm.c | 5 +----
src/cpu/cpu_s390.c | 5 +----
src/cpu/cpu_x86.c | 13 ++++---------
src/qemu/qemu_domain.c | 6 ------
src/qemu/qemu_driver.c | 3 +--
src/qemu/qemu_process.c | 3 +--
8 files changed, 13 insertions(+), 32 deletions(-)
diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 1227db1201..3b824e85d2 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -233,9 +233,6 @@ virCPUDefCopyWithoutModel(const virCPUDef *cpu)
{
g_autoptr(virCPUDef) copy = NULL;
- if (!cpu)
- return NULL;
-
copy = virCPUDefNew();
copy->type = cpu->type;
copy->mode = cpu->mode;
@@ -276,9 +273,11 @@ virCPUDefCopy(const virCPUDef *cpu)
{
g_autoptr(virCPUDef) copy = NULL;
- if (!(copy = virCPUDefCopyWithoutModel(cpu)))
+ if (!cpu)
return NULL;
+ copy = virCPUDefCopyWithoutModel(cpu);
+
virCPUDefCopyModel(copy, cpu, false);
return g_steal_pointer(©);
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index 5d69b4d2e0..560b597777 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -204,7 +204,8 @@ virCPUDef *
virCPUDefCopy(const virCPUDef *cpu);
virCPUDef *
-virCPUDefCopyWithoutModel(const virCPUDef *cpu);
+virCPUDefCopyWithoutModel(const virCPUDef *cpu)
+ ATTRIBUTE_NONNULL(1);
int
virCPUDefParseXMLString(const char *xml,
diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c
index a890ed6ba3..8e562bd7a3 100644
--- a/src/cpu/cpu_arm.c
+++ b/src/cpu/cpu_arm.c
@@ -450,7 +450,7 @@ virCPUarmUpdate(virCPUDef *guest,
const virCPUDef *host,
bool relative)
{
- g_autoptr(virCPUDef) updated = NULL;
+ g_autoptr(virCPUDef) updated = virCPUDefCopyWithoutModel(guest);
if (!relative || guest->mode != VIR_CPU_MODE_HOST_MODEL)
return 0;
@@ -461,9 +461,6 @@ virCPUarmUpdate(virCPUDef *guest,
return -1;
}
- if (!(updated = virCPUDefCopyWithoutModel(guest)))
- return -1;
-
updated->mode = VIR_CPU_MODE_CUSTOM;
virCPUDefCopyModel(updated, host, true);
diff --git a/src/cpu/cpu_s390.c b/src/cpu/cpu_s390.c
index 0f3b5c6820..1de5251974 100644
--- a/src/cpu/cpu_s390.c
+++ b/src/cpu/cpu_s390.c
@@ -44,7 +44,7 @@ virCPUs390Update(virCPUDef *guest,
const virCPUDef *host,
bool relative)
{
- g_autoptr(virCPUDef) updated = NULL;
+ g_autoptr(virCPUDef) updated = virCPUDefCopyWithoutModel(guest);
size_t i;
if (!relative)
@@ -68,9 +68,6 @@ virCPUs390Update(virCPUDef *guest,
return -1;
}
- if (!(updated = virCPUDefCopyWithoutModel(guest)))
- return -1;
-
updated->mode = VIR_CPU_MODE_CUSTOM;
virCPUDefCopyModel(updated, host, true);
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 2fede8e5fa..6560b7a502 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -2935,12 +2935,9 @@ static int
x86UpdateHostModel(virCPUDef *guest,
const virCPUDef *host)
{
- g_autoptr(virCPUDef) updated = NULL;
+ g_autoptr(virCPUDef) updated = virCPUDefCopyWithoutModel(host);
size_t i;
- if (!(updated = virCPUDefCopyWithoutModel(host)))
- return -1;
-
updated->type = VIR_CPU_TYPE_GUEST;
updated->mode = VIR_CPU_MODE_CUSTOM;
virCPUDefCopyModel(updated, host, true);
@@ -3169,7 +3166,7 @@ static int
virCPUx86Translate(virCPUDef *cpu,
virDomainCapsCPUModels *models)
{
- g_autoptr(virCPUDef) translated = NULL;
+ g_autoptr(virCPUDef) translated = virCPUDefCopyWithoutModel(cpu);
virCPUx86Map *map;
g_autoptr(virCPUx86Model) model = NULL;
size_t i;
@@ -3191,9 +3188,6 @@ virCPUx86Translate(virCPUDef *cpu,
return -1;
}
- if (!(translated = virCPUDefCopyWithoutModel(cpu)))
- return -1;
-
if (x86Decode(translated, &model->data, models, NULL, false) < 0)
return -1;
@@ -3280,9 +3274,10 @@ virCPUx86CopyMigratable(virCPUDef *cpu)
if (!(map = virCPUx86GetMap()))
return NULL;
- if (!(copy = virCPUDefCopyWithoutModel(cpu)))
+ if (!cpu)
return NULL;
+ copy = virCPUDefCopyWithoutModel(cpu);
virCPUDefCopyModelFilter(copy, cpu, false, x86FeatureFilterMigratable, map);
return g_steal_pointer(©);
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 9791fa1dca..707fa92cf4 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -10778,9 +10778,6 @@ qemuDomainFixupCPUs(virDomainObj *vm,
if (virCPUDefFindFeature(vm->def->cpu, "cmt")) {
g_autoptr(virCPUDef) fixedCPU = virCPUDefCopyWithoutModel(vm->def->cpu);
- if (!fixedCPU)
- return -1;
-
virCPUDefCopyModelFilter(fixedCPU, vm->def->cpu, false,
virQEMUCapsCPUFilterFeatures, &arch);
@@ -10791,9 +10788,6 @@ qemuDomainFixupCPUs(virDomainObj *vm,
if (virCPUDefFindFeature(*origCPU, "cmt")) {
g_autoptr(virCPUDef) fixedOrig = virCPUDefCopyWithoutModel(*origCPU);
- if (!fixedOrig)
- return -1;
-
virCPUDefCopyModelFilter(fixedOrig, *origCPU, false,
virQEMUCapsCPUFilterFeatures, &arch);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 146318c6db..e64a061843 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12193,8 +12193,7 @@ qemuConnectBaselineCPU(virConnectPtr conn G_GNUC_UNUSED,
!!(flags &
VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
goto cleanup;
- if (!(cpu = virCPUDefCopyWithoutModel(baseline)))
- goto cleanup;
+ cpu = virCPUDefCopyWithoutModel(baseline);
virCPUDefCopyModelFilter(cpu, baseline, false, virQEMUCapsCPUFilterFeatures,
&cpus[0]->arch);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 27973a2e03..eb1797688c 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8853,8 +8853,7 @@ qemuProcessRefreshCPU(virQEMUDriver *driver,
if (!(hostmig = virCPUCopyMigratable(host->arch, host)))
return -1;
- if (!(cpu = virCPUDefCopyWithoutModel(hostmig)))
- return -1;
+ cpu = virCPUDefCopyWithoutModel(hostmig);
virCPUDefCopyModelFilter(cpu, hostmig, false, virQEMUCapsCPUFilterFeatures,
&host->arch);
--
2.39.2