1
0

conf: virDomainCapsCPUModelsAdd never fails

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Jiri Denemark 2022-09-29 16:30:19 +02:00
parent 8ef8d9e21b
commit f0554d88fb
4 changed files with 23 additions and 35 deletions

View File

@ -155,37 +155,33 @@ virDomainCapsCPUModelsNew(size_t nmodels)
virDomainCapsCPUModels * virDomainCapsCPUModels *
virDomainCapsCPUModelsCopy(virDomainCapsCPUModels *old) virDomainCapsCPUModelsCopy(virDomainCapsCPUModels *old)
{ {
g_autoptr(virDomainCapsCPUModels) cpuModels = NULL; virDomainCapsCPUModels *cpuModels = NULL;
size_t i; size_t i;
if (!(cpuModels = virDomainCapsCPUModelsNew(old->nmodels))) if (!(cpuModels = virDomainCapsCPUModelsNew(old->nmodels)))
return NULL; return NULL;
for (i = 0; i < old->nmodels; i++) { for (i = 0; i < old->nmodels; i++) {
if (virDomainCapsCPUModelsAdd(cpuModels, virDomainCapsCPUModelsAdd(cpuModels,
old->models[i].name, old->models[i].name,
old->models[i].usable, old->models[i].usable,
old->models[i].blockers, old->models[i].blockers,
old->models[i].deprecated) < 0) old->models[i].deprecated);
return NULL;
} }
return g_steal_pointer(&cpuModels); return cpuModels;
} }
int void
virDomainCapsCPUModelsAdd(virDomainCapsCPUModels *cpuModels, virDomainCapsCPUModelsAdd(virDomainCapsCPUModels *cpuModels,
const char *name, const char *name,
virDomainCapsCPUUsable usable, virDomainCapsCPUUsable usable,
char **blockers, char **blockers,
bool deprecated) bool deprecated)
{ {
g_autofree char * nameCopy = NULL;
virDomainCapsCPUModel *cpu; virDomainCapsCPUModel *cpu;
nameCopy = g_strdup(name);
VIR_RESIZE_N(cpuModels->models, cpuModels->nmodels_max, VIR_RESIZE_N(cpuModels->models, cpuModels->nmodels_max,
cpuModels->nmodels, 1); cpuModels->nmodels, 1);
@ -193,11 +189,9 @@ virDomainCapsCPUModelsAdd(virDomainCapsCPUModels *cpuModels,
cpuModels->nmodels++; cpuModels->nmodels++;
cpu->usable = usable; cpu->usable = usable;
cpu->name = g_steal_pointer(&nameCopy); cpu->name = g_strdup(name);
cpu->blockers = g_strdupv(blockers); cpu->blockers = g_strdupv(blockers);
cpu->deprecated = deprecated; cpu->deprecated = deprecated;
return 0;
} }

View File

@ -244,11 +244,12 @@ virDomainCaps *virDomainCapsNew(const char *path,
virDomainCapsCPUModels *virDomainCapsCPUModelsNew(size_t nmodels); virDomainCapsCPUModels *virDomainCapsCPUModelsNew(size_t nmodels);
virDomainCapsCPUModels *virDomainCapsCPUModelsCopy(virDomainCapsCPUModels *old); virDomainCapsCPUModels *virDomainCapsCPUModelsCopy(virDomainCapsCPUModels *old);
int virDomainCapsCPUModelsAdd(virDomainCapsCPUModels *cpuModels, void
const char *name, virDomainCapsCPUModelsAdd(virDomainCapsCPUModels *cpuModels,
virDomainCapsCPUUsable usable, const char *name,
char **blockers, virDomainCapsCPUUsable usable,
bool deprecated); char **blockers,
bool deprecated);
virDomainCapsCPUModel * virDomainCapsCPUModel *
virDomainCapsCPUModelsGet(virDomainCapsCPUModels *cpuModels, virDomainCapsCPUModelsGet(virDomainCapsCPUModels *cpuModels,
const char *name); const char *name);

View File

@ -2179,7 +2179,7 @@ virQEMUCapsCPUDefsToModels(qemuMonitorCPUDefs *defs,
const char **modelAllowed, const char **modelAllowed,
const char **modelForbidden) const char **modelForbidden)
{ {
g_autoptr(virDomainCapsCPUModels) cpuModels = NULL; virDomainCapsCPUModels *cpuModels = NULL;
size_t i; size_t i;
if (!(cpuModels = virDomainCapsCPUModelsNew(defs->ncpus))) if (!(cpuModels = virDomainCapsCPUModelsNew(defs->ncpus)))
@ -2194,12 +2194,11 @@ virQEMUCapsCPUDefsToModels(qemuMonitorCPUDefs *defs,
if (modelForbidden && g_strv_contains(modelForbidden, cpu->name)) if (modelForbidden && g_strv_contains(modelForbidden, cpu->name))
continue; continue;
if (virDomainCapsCPUModelsAdd(cpuModels, cpu->name, cpu->usable, virDomainCapsCPUModelsAdd(cpuModels, cpu->name, cpu->usable,
cpu->blockers, cpu->deprecated) < 0) cpu->blockers, cpu->deprecated);
return NULL;
} }
return g_steal_pointer(&cpuModels); return cpuModels;
} }

View File

@ -823,9 +823,8 @@ cpuTestUpdateLive(const void *arg)
usable = hvModel->usable; usable = hvModel->usable;
} }
if (virDomainCapsCPUModelsAdd(models, expected->model, virDomainCapsCPUModelsAdd(models, expected->model,
usable, blockers, false) < 0) usable, blockers, false);
return -1;
cpu->fallback = VIR_CPU_FALLBACK_ALLOW; cpu->fallback = VIR_CPU_FALLBACK_ALLOW;
ignore_value(virCPUTranslate(data->arch, cpu, models)); ignore_value(virCPUTranslate(data->arch, cpu, models));
@ -902,16 +901,11 @@ cpuTestInitModels(const char **list)
return NULL; return NULL;
for (model = list; *model; model++) { for (model = list; *model; model++) {
if (virDomainCapsCPUModelsAdd(cpus, *model, virDomainCapsCPUModelsAdd(cpus, *model,
VIR_DOMCAPS_CPU_USABLE_UNKNOWN, NULL, false) < 0) VIR_DOMCAPS_CPU_USABLE_UNKNOWN, NULL, false);
goto error;
} }
return cpus; return cpus;
error:
virObjectUnref(cpus);
return NULL;
} }