[libvirt PATCH 01/11] conf: virDomainCapsCPUModelsAdd never fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Since the function always returns 0, we can just return void and make
callers simpler.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/conf/domain_capabilities.c | 24 +++++++++---------------
 src/conf/domain_capabilities.h | 11 ++++++-----
 src/qemu/qemu_capabilities.c   |  9 ++++-----
 tests/cputest.c                | 14 ++++----------
 4 files changed, 23 insertions(+), 35 deletions(-)

diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c
index 653123f293..123c80a560 100644
--- a/src/conf/domain_capabilities.c
+++ b/src/conf/domain_capabilities.c
@@ -155,37 +155,33 @@ virDomainCapsCPUModelsNew(size_t nmodels)
 virDomainCapsCPUModels *
 virDomainCapsCPUModelsCopy(virDomainCapsCPUModels *old)
 {
-    g_autoptr(virDomainCapsCPUModels) cpuModels = NULL;
+    virDomainCapsCPUModels *cpuModels = NULL;
     size_t i;
 
     if (!(cpuModels = virDomainCapsCPUModelsNew(old->nmodels)))
         return NULL;
 
     for (i = 0; i < old->nmodels; i++) {
-        if (virDomainCapsCPUModelsAdd(cpuModels,
-                                      old->models[i].name,
-                                      old->models[i].usable,
-                                      old->models[i].blockers,
-                                      old->models[i].deprecated) < 0)
-            return NULL;
+        virDomainCapsCPUModelsAdd(cpuModels,
+                                  old->models[i].name,
+                                  old->models[i].usable,
+                                  old->models[i].blockers,
+                                  old->models[i].deprecated);
     }
 
-    return g_steal_pointer(&cpuModels);
+    return cpuModels;
 }
 
 
-int
+void
 virDomainCapsCPUModelsAdd(virDomainCapsCPUModels *cpuModels,
                           const char *name,
                           virDomainCapsCPUUsable usable,
                           char **blockers,
                           bool deprecated)
 {
-    g_autofree char * nameCopy = NULL;
     virDomainCapsCPUModel *cpu;
 
-    nameCopy = g_strdup(name);
-
     VIR_RESIZE_N(cpuModels->models, cpuModels->nmodels_max,
                  cpuModels->nmodels, 1);
 
@@ -193,11 +189,9 @@ virDomainCapsCPUModelsAdd(virDomainCapsCPUModels *cpuModels,
     cpuModels->nmodels++;
 
     cpu->usable = usable;
-    cpu->name = g_steal_pointer(&nameCopy);
+    cpu->name = g_strdup(name);
     cpu->blockers = g_strdupv(blockers);
     cpu->deprecated = deprecated;
-
-    return 0;
 }
 
 
diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h
index a526969cda..7333276231 100644
--- a/src/conf/domain_capabilities.h
+++ b/src/conf/domain_capabilities.h
@@ -244,11 +244,12 @@ virDomainCaps *virDomainCapsNew(const char *path,
 
 virDomainCapsCPUModels *virDomainCapsCPUModelsNew(size_t nmodels);
 virDomainCapsCPUModels *virDomainCapsCPUModelsCopy(virDomainCapsCPUModels *old);
-int virDomainCapsCPUModelsAdd(virDomainCapsCPUModels *cpuModels,
-                              const char *name,
-                              virDomainCapsCPUUsable usable,
-                              char **blockers,
-                              bool deprecated);
+void
+virDomainCapsCPUModelsAdd(virDomainCapsCPUModels *cpuModels,
+                          const char *name,
+                          virDomainCapsCPUUsable usable,
+                          char **blockers,
+                          bool deprecated);
 virDomainCapsCPUModel *
 virDomainCapsCPUModelsGet(virDomainCapsCPUModels *cpuModels,
                           const char *name);
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 50bde370e8..2a0be77631 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2179,7 +2179,7 @@ virQEMUCapsCPUDefsToModels(qemuMonitorCPUDefs *defs,
                            const char **modelAllowed,
                            const char **modelForbidden)
 {
-    g_autoptr(virDomainCapsCPUModels) cpuModels = NULL;
+    virDomainCapsCPUModels *cpuModels = NULL;
     size_t i;
 
     if (!(cpuModels = virDomainCapsCPUModelsNew(defs->ncpus)))
@@ -2194,12 +2194,11 @@ virQEMUCapsCPUDefsToModels(qemuMonitorCPUDefs *defs,
         if (modelForbidden && g_strv_contains(modelForbidden, cpu->name))
             continue;
 
-        if (virDomainCapsCPUModelsAdd(cpuModels, cpu->name, cpu->usable,
-                                      cpu->blockers, cpu->deprecated) < 0)
-            return NULL;
+        virDomainCapsCPUModelsAdd(cpuModels, cpu->name, cpu->usable,
+                                  cpu->blockers, cpu->deprecated);
     }
 
-    return g_steal_pointer(&cpuModels);
+    return cpuModels;
 }
 
 
diff --git a/tests/cputest.c b/tests/cputest.c
index b7ec79dfc6..9d24b9d0f5 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -823,9 +823,8 @@ cpuTestUpdateLive(const void *arg)
             usable = hvModel->usable;
         }
 
-        if (virDomainCapsCPUModelsAdd(models, expected->model,
-                                      usable, blockers, false) < 0)
-            return -1;
+        virDomainCapsCPUModelsAdd(models, expected->model,
+                                  usable, blockers, false);
 
         cpu->fallback = VIR_CPU_FALLBACK_ALLOW;
         ignore_value(virCPUTranslate(data->arch, cpu, models));
@@ -902,16 +901,11 @@ cpuTestInitModels(const char **list)
         return NULL;
 
     for (model = list; *model; model++) {
-        if (virDomainCapsCPUModelsAdd(cpus, *model,
-                                      VIR_DOMCAPS_CPU_USABLE_UNKNOWN, NULL, false) < 0)
-            goto error;
+        virDomainCapsCPUModelsAdd(cpus, *model,
+                                  VIR_DOMCAPS_CPU_USABLE_UNKNOWN, NULL, false);
     }
 
     return cpus;
-
- error:
-    virObjectUnref(cpus);
-    return NULL;
 }
 
 
-- 
2.37.3




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux