diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index b554ec59dd3a950d232d54fbac9baab306b85112..4263d1e134786756fedbc5adcd5aa0d91ea26672 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -431,7 +431,7 @@ x86DataToCPUFeatures(virCPUDefPtr cpu, /* also removes bits corresponding to vendor string from data */ static virCPUx86VendorPtr -x86DataToVendor(virCPUx86Data *data, +x86DataToVendor(const virCPUx86Data *data, virCPUx86MapPtr map) { virCPUx86VendorPtr vendor = map->vendors; @@ -1591,6 +1591,7 @@ x86Decode(virCPUDefPtr cpu, virCPUx86Data *copy = NULL; virCPUx86Data *features = NULL; const virCPUx86Data *cpuData = NULL; + virCPUx86VendorPtr vendor; size_t i; int rc; @@ -1600,6 +1601,8 @@ x86Decode(virCPUDefPtr cpu, if (!data || !(map = virCPUx86GetMap())) return -1; + vendor = x86DataToVendor(data, map); + for (candidate = map->models; candidate; candidate = candidate->next) { if (!cpuModelIsAllowed(candidate->name, models, nmodels)) { if (preferred && STREQ(candidate->name, preferred)) { @@ -1620,19 +1623,19 @@ x86Decode(virCPUDefPtr cpu, continue; } - if (!(cpuCandidate = x86DataToCPU(data, candidate, map))) - goto cleanup; - cpuCandidate->type = cpu->type; - - if (candidate->vendor && cpuCandidate->vendor && - STRNEQ(candidate->vendor->name, cpuCandidate->vendor)) { + /* Both vendor and candidate->vendor are pointers to a single list of + * known vendors stored in the map. + */ + if (vendor && candidate->vendor && vendor != candidate->vendor) { VIR_DEBUG("CPU vendor %s of model %s differs from %s; ignoring", - candidate->vendor->name, candidate->name, - cpuCandidate->vendor); - virCPUDefFree(cpuCandidate); + candidate->vendor->name, candidate->name, vendor->name); continue; } + if (!(cpuCandidate = x86DataToCPU(data, candidate, map))) + goto cleanup; + cpuCandidate->type = cpu->type; + if ((rc = x86DecodeUseCandidate(cpuModel, cpuCandidate, preferred, cpu->type == VIR_CPU_TYPE_HOST))) { virCPUDefFree(cpuModel); @@ -1677,8 +1680,10 @@ x86Decode(virCPUDefPtr cpu, goto cleanup; } + if (vendor && VIR_STRDUP(cpu->vendor, vendor->name) < 0) + goto cleanup; + cpu->model = cpuModel->model; - cpu->vendor = cpuModel->vendor; cpu->nfeatures = cpuModel->nfeatures; cpu->features = cpuModel->features; VIR_FREE(cpuModel);