summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlauber Costa <glommer@redhat.com>2009-07-14 11:35:13 -0400
committerMarcelo Tosatti <mtosatti@redhat.com>2009-07-14 19:37:29 -0300
commitf070832cdc749a06d2c72789e6cbd0c5dce799c0 (patch)
tree2d80a4b88f84e7fe7aacfb16cb4d9de596ec205f /qemu-kvm-x86.c
parentDo not compile qemu-kvm.c and qemu-kvm-x86.c (diff)
downloadqemu-kvm-f070832cdc749a06d2c72789e6cbd0c5dce799c0.tar.gz
qemu-kvm-f070832cdc749a06d2c72789e6cbd0c5dce799c0.tar.bz2
qemu-kvm-f070832cdc749a06d2c72789e6cbd0c5dce799c0.zip
replace malloc with qemu_malloc
This patch replaces both malloc and malloc+memset sequences with qemu_malloc and qemu_mallocz. Target is upstream integration Signed-off-by: Glauber Costa <glommer@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'qemu-kvm-x86.c')
-rw-r--r--qemu-kvm-x86.c31
1 files changed, 8 insertions, 23 deletions
diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index daf60b6bf..e953391d0 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -390,12 +390,9 @@ struct kvm_msr_list *kvm_get_msr_list(kvm_context_t kvm)
return NULL;
/* Old kernel modules had a bug and could write beyond the provided
memory. Allocate at least a safe amount of 1K. */
- msrs = malloc(MAX(1024, sizeof(*msrs) +
- sizer.nmsrs * sizeof(*msrs->indices)));
- if (!msrs) {
- errno = ENOMEM;
- return NULL;
- }
+ msrs = qemu_malloc(MAX(1024, sizeof(*msrs) +
+ sizer.nmsrs * sizeof(*msrs->indices)));
+
msrs->nmsrs = sizer.nmsrs;
r = ioctl(kvm->fd, KVM_GET_MSR_INDEX_LIST, msrs);
if (r == -1) {
@@ -409,13 +406,9 @@ struct kvm_msr_list *kvm_get_msr_list(kvm_context_t kvm)
int kvm_get_msrs(kvm_vcpu_context_t vcpu, struct kvm_msr_entry *msrs, int n)
{
- struct kvm_msrs *kmsrs = malloc(sizeof *kmsrs + n * sizeof *msrs);
+ struct kvm_msrs *kmsrs = qemu_malloc(sizeof *kmsrs + n * sizeof *msrs);
int r, e;
- if (!kmsrs) {
- errno = ENOMEM;
- return -1;
- }
kmsrs->nmsrs = n;
memcpy(kmsrs->entries, msrs, n * sizeof *msrs);
r = ioctl(vcpu->fd, KVM_GET_MSRS, kmsrs);
@@ -428,13 +421,9 @@ int kvm_get_msrs(kvm_vcpu_context_t vcpu, struct kvm_msr_entry *msrs, int n)
int kvm_set_msrs(kvm_vcpu_context_t vcpu, struct kvm_msr_entry *msrs, int n)
{
- struct kvm_msrs *kmsrs = malloc(sizeof *kmsrs + n * sizeof *msrs);
+ struct kvm_msrs *kmsrs = qemu_malloc(sizeof *kmsrs + n * sizeof *msrs);
int r, e;
- if (!kmsrs) {
- errno = ENOMEM;
- return -1;
- }
kmsrs->nmsrs = n;
memcpy(kmsrs->entries, msrs, n * sizeof *msrs);
r = ioctl(vcpu->fd, KVM_SET_MSRS, kmsrs);
@@ -524,9 +513,7 @@ int kvm_setup_cpuid(kvm_vcpu_context_t vcpu, int nent,
struct kvm_cpuid *cpuid;
int r;
- cpuid = malloc(sizeof(*cpuid) + nent * sizeof(*entries));
- if (!cpuid)
- return -ENOMEM;
+ cpuid = qemu_malloc(sizeof(*cpuid) + nent * sizeof(*entries));
cpuid->nent = nent;
memcpy(cpuid->entries, entries, nent * sizeof(*entries));
@@ -542,9 +529,7 @@ int kvm_setup_cpuid2(kvm_vcpu_context_t vcpu, int nent,
struct kvm_cpuid2 *cpuid;
int r;
- cpuid = malloc(sizeof(*cpuid) + nent * sizeof(*entries));
- if (!cpuid)
- return -ENOMEM;
+ cpuid = qemu_malloc(sizeof(*cpuid) + nent * sizeof(*entries));
cpuid->nent = nent;
memcpy(cpuid->entries, entries, nent * sizeof(*entries));
@@ -632,7 +617,7 @@ static struct kvm_cpuid2 *try_get_cpuid(kvm_context_t kvm, int max)
int r, size;
size = sizeof(*cpuid) + max * sizeof(*cpuid->entries);
- cpuid = (struct kvm_cpuid2 *)malloc(size);
+ cpuid = qemu_malloc(size);
cpuid->nent = max;
r = ioctl(kvm->fd, KVM_GET_SUPPORTED_CPUID, cpuid);
if (r == -1)