From patchwork Wed Jul 8 13:08:58 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 34611 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n68D9Fac016568 for ; Wed, 8 Jul 2009 13:09:16 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754342AbZGHNJK (ORCPT ); Wed, 8 Jul 2009 09:09:10 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754588AbZGHNJJ (ORCPT ); Wed, 8 Jul 2009 09:09:09 -0400 Received: from mx2.redhat.com ([66.187.237.31]:38644 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753719AbZGHNJH (ORCPT ); Wed, 8 Jul 2009 09:09:07 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n68D96a3026578 for ; Wed, 8 Jul 2009 09:09:06 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n68D95Rf024281; Wed, 8 Jul 2009 09:09:06 -0400 Received: from localhost.localdomain (virtlab1.virt.bos.redhat.com [10.16.72.21]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n68D92uH029245; Wed, 8 Jul 2009 09:09:05 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: avi@redhat.com Subject: [PATCH 4/8] replace malloc with qemu_malloc Date: Wed, 8 Jul 2009 09:08:58 -0400 Message-Id: <1247058542-31211-5-git-send-email-glommer@redhat.com> In-Reply-To: <1247058542-31211-4-git-send-email-glommer@redhat.com> References: <1247058542-31211-1-git-send-email-glommer@redhat.com> <1247058542-31211-2-git-send-email-glommer@redhat.com> <1247058542-31211-3-git-send-email-glommer@redhat.com> <1247058542-31211-4-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patch replaces both malloc and malloc+memset sequences with qemu_malloc and qemu_mallocz. Target is upstream integration Signed-off-by: Glauber Costa --- kvm-all.c | 26 +++++--------------------- target-i386/kvm.c | 31 ++++++++----------------------- 2 files changed, 13 insertions(+), 44 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index fd68f4c..034ae52 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1469,10 +1469,7 @@ kvm_context_t kvm_init(void *opaque) } kvm_abi = r; kvm_page_size = getpagesize(); - kvm = malloc(sizeof(*kvm)); - if (kvm == NULL) - goto out_close; - memset(kvm, 0, sizeof(*kvm)); + kvm = qemu_mallocz(sizeof(*kvm)); kvm->fd = fd; kvm->vm_fd = -1; kvm->opaque = opaque; @@ -1486,10 +1483,7 @@ kvm_context_t kvm_init(void *opaque) /* Round up so we can search ints using ffs */ gsi_bits = ALIGN(gsi_count, 32); - kvm->used_gsi_bitmap = malloc(gsi_bits / 8); - if (!kvm->used_gsi_bitmap) - goto out_close; - memset(kvm->used_gsi_bitmap, 0, gsi_bits / 8); + kvm->used_gsi_bitmap = qemu_mallocz(gsi_bits / 8); kvm->max_gsi = gsi_bits; /* Mark any over-allocated bits as already in use */ @@ -1529,12 +1523,7 @@ kvm_vcpu_context_t kvm_create_vcpu(kvm_context_t kvm, int id) { long mmap_size; int r; - kvm_vcpu_context_t vcpu_ctx = malloc(sizeof(struct kvm_vcpu_context)); - - if (!vcpu_ctx) { - errno = ENOMEM; - return NULL; - } + kvm_vcpu_context_t vcpu_ctx = qemu_malloc(sizeof(struct kvm_vcpu_context)); vcpu_ctx->kvm = kvm; vcpu_ctx->id = id; @@ -1581,10 +1570,7 @@ int kvm_create_vm(kvm_context_t kvm) int fd = kvm->fd; #ifdef KVM_CAP_IRQ_ROUTING - kvm->irq_routes = malloc(sizeof(*kvm->irq_routes)); - if (!kvm->irq_routes) - return -ENOMEM; - memset(kvm->irq_routes, 0, sizeof(*kvm->irq_routes)); + kvm->irq_routes = qemu_mallocz(sizeof(*kvm->irq_routes)); kvm->nr_allocated_irq_routes = 0; #endif @@ -2189,9 +2175,7 @@ int kvm_set_signal_mask(kvm_vcpu_context_t vcpu, const sigset_t *sigset) r = -errno; return r; } - sigmask = malloc(sizeof(*sigmask) + sizeof(*sigset)); - if (!sigmask) - return -ENOMEM; + sigmask = qemu_malloc(sizeof(*sigmask) + sizeof(*sigset)); sigmask->len = 8; memcpy(sigmask->sigset, sigset, sizeof(*sigset)); diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 4c3948c..ab324f6 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -1303,12 +1303,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) { @@ -1322,13 +1319,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); @@ -1341,13 +1334,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); @@ -1437,9 +1426,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)); @@ -1455,9 +1442,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)); @@ -1545,7 +1530,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)