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 *
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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}