@@ -567,34 +567,33 @@ static struct kvm_cpuid_entry2 *do_host_cpuid(struct kvm_cpuid_array *array,
static int __do_cpuid_func_emulated(struct kvm_cpuid_array *array, u32 func)
{
- struct kvm_cpuid_entry2 *entry;
-
- if (array->nent >= array->maxnent)
- return -E2BIG;
+ struct kvm_cpuid_entry2 entry;
- entry = &array->entries[array->nent];
- entry->function = func;
- entry->index = 0;
- entry->flags = 0;
+ memset(&entry, 0, sizeof(entry));
switch (func) {
case 0:
- entry->eax = 7;
- ++array->nent;
+ entry.eax = 7;
break;
case 1:
- entry->ecx = F(MOVBE);
- ++array->nent;
+ entry.ecx = F(MOVBE);
break;
case 7:
- entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
- entry->eax = 0;
- entry->ecx = F(RDPID);
- ++array->nent;
- default:
+ entry.flags = KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
+ entry.ecx = F(RDPID);
break;
+ default:
+ goto out;
}
+ /* Check the array capacity iff the entry is being copied over. */
+ if (array->nent >= array->maxnent)
+ return -E2BIG;
+
+ entry.function = func;
+ memcpy(&array->entries[array->nent++], &entry, sizeof(entry));
+
+out:
return 0;
}