[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] use xzalloc in common code



# HG changeset patch
# User Jan Beulich <jbeulich@xxxxxxxx>
# Date 1317730592 -7200
# Node ID a42af55d50fb7267126feb84df7b7e687db60ca5
# Parent  e09ebf7a31f55bb26c3cce7695a435ed20adf05b
use xzalloc in common code

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
Acked-by: Keir Fraser <keir@xxxxxxx>
---


diff -r e09ebf7a31f5 -r a42af55d50fb xen/common/cpupool.c
--- a/xen/common/cpupool.c      Tue Oct 04 14:15:26 2011 +0200
+++ b/xen/common/cpupool.c      Tue Oct 04 14:16:32 2011 +0200
@@ -39,7 +39,7 @@
 
 static struct cpupool *alloc_cpupool_struct(void)
 {
-    return xmalloc(struct cpupool);
+    return xzalloc(struct cpupool);
 }
 
 static void free_cpupool_struct(struct cpupool *c)
@@ -118,7 +118,6 @@
     *perr = -ENOMEM;
     if ( (c = alloc_cpupool_struct()) == NULL )
         return NULL;
-    memset(c, 0, sizeof(*c));
 
     /* One reference for caller, one reference for cpupool_destroy(). */
     atomic_set(&c->refcnt, 2);
diff -r e09ebf7a31f5 -r a42af55d50fb xen/common/domctl.c
--- a/xen/common/domctl.c       Tue Oct 04 14:15:26 2011 +0200
+++ b/xen/common/domctl.c       Tue Oct 04 14:16:32 2011 +0200
@@ -155,11 +155,9 @@
 
     /* Do an initial CPU placement. Pick the least-populated CPU. */
     nr_cpus = last_cpu(cpu_online_map) + 1;
-    cnt = xmalloc_array(unsigned int, nr_cpus);
+    cnt = xzalloc_array(unsigned int, nr_cpus);
     if ( cnt )
     {
-        memset(cnt, 0, nr_cpus * sizeof(*cnt));
-
         rcu_read_lock(&domlist_read_lock);
         for_each_domain ( d )
             for_each_vcpu ( d, v )
@@ -511,9 +509,8 @@
             BUG_ON(d->vcpu != NULL);
             BUG_ON(d->max_vcpus != 0);
 
-            if ( (vcpus = xmalloc_array(struct vcpu *, max)) == NULL )
+            if ( (vcpus = xzalloc_array(struct vcpu *, max)) == NULL )
                 goto maxvcpu_out;
-            memset(vcpus, 0, max * sizeof(*vcpus));
 
             /* Install vcpu array /then/ update max_vcpus. */
             d->vcpu = vcpus;
diff -r e09ebf7a31f5 -r a42af55d50fb xen/common/event_channel.c
--- a/xen/common/event_channel.c        Tue Oct 04 14:15:26 2011 +0200
+++ b/xen/common/event_channel.c        Tue Oct 04 14:16:32 2011 +0200
@@ -100,10 +100,9 @@
     if ( port == MAX_EVTCHNS(d) )
         return -ENOSPC;
 
-    chn = xmalloc_array(struct evtchn, EVTCHNS_PER_BUCKET);
+    chn = xzalloc_array(struct evtchn, EVTCHNS_PER_BUCKET);
     if ( unlikely(chn == NULL) )
         return -ENOMEM;
-    memset(chn, 0, EVTCHNS_PER_BUCKET * sizeof(*chn));
     bucket_from_port(d, port) = chn;
 
     for ( i = 0; i < EVTCHNS_PER_BUCKET; i++ )
diff -r e09ebf7a31f5 -r a42af55d50fb xen/common/grant_table.c
--- a/xen/common/grant_table.c  Tue Oct 04 14:15:26 2011 +0200
+++ b/xen/common/grant_table.c  Tue Oct 04 14:16:32 2011 +0200
@@ -2400,19 +2400,17 @@
     struct grant_table *t;
     int                 i;
 
-    if ( (t = xmalloc(struct grant_table)) == NULL )
+    if ( (t = xzalloc(struct grant_table)) == NULL )
         goto no_mem_0;
 
     /* Simple stuff. */
-    memset(t, 0, sizeof(*t));
     spin_lock_init(&t->lock);
     t->nr_grant_frames = INITIAL_NR_GRANT_FRAMES;
 
     /* Active grant table. */
-    if ( (t->active = xmalloc_array(struct active_grant_entry *,
+    if ( (t->active = xzalloc_array(struct active_grant_entry *,
                                     max_nr_active_grant_frames())) == NULL )
         goto no_mem_1;
-    memset(t->active, 0, max_nr_active_grant_frames() * sizeof(t->active[0]));
     for ( i = 0;
           i < num_act_frames_from_sha_frames(INITIAL_NR_GRANT_FRAMES); i++ )
     {
@@ -2422,10 +2420,9 @@
     }
 
     /* Tracking of mapped foreign frames table */
-    if ( (t->maptrack = xmalloc_array(struct grant_mapping *,
+    if ( (t->maptrack = xzalloc_array(struct grant_mapping *,
                                       max_nr_maptrack_frames())) == NULL )
         goto no_mem_2;
-    memset(t->maptrack, 0, max_nr_maptrack_frames() * sizeof(t->maptrack[0]));
     if ( (t->maptrack[0] = alloc_xenheap_page()) == NULL )
         goto no_mem_3;
     clear_page(t->maptrack[0]);
@@ -2434,9 +2431,8 @@
         t->maptrack[0][i].ref = i+1;
 
     /* Shared grant table. */
-    if ( (t->shared_raw = xmalloc_array(void *, max_nr_grant_frames)) == NULL )
+    if ( (t->shared_raw = xzalloc_array(void *, max_nr_grant_frames)) == NULL )
         goto no_mem_3;
-    memset(t->shared_raw, 0, max_nr_grant_frames * sizeof(t->shared_raw[0]));
     for ( i = 0; i < INITIAL_NR_GRANT_FRAMES; i++ )
     {
         if ( (t->shared_raw[i] = alloc_xenheap_page()) == NULL )
@@ -2448,12 +2444,10 @@
         gnttab_create_shared_page(d, t, i);
 
     /* Status pages for grant table - for version 2 */
-    t->status = xmalloc_array(grant_status_t *,
+    t->status = xzalloc_array(grant_status_t *,
                               grant_to_status_frames(max_nr_grant_frames));
     if ( t->status == NULL )
         goto no_mem_4;
-    memset(t->status, 0,
-           grant_to_status_frames(max_nr_grant_frames) * sizeof(t->status[0]));
     t->nr_status_frames = 0;
 
     /* Okay, install the structure. */
diff -r e09ebf7a31f5 -r a42af55d50fb xen/common/sched_arinc653.c
--- a/xen/common/sched_arinc653.c       Tue Oct 04 14:15:26 2011 +0200
+++ b/xen/common/sched_arinc653.c       Tue Oct 04 14:16:32 2011 +0200
@@ -341,11 +341,10 @@
 {
     a653sched_priv_t *prv;
 
-    prv = xmalloc(a653sched_priv_t);
+    prv = xzalloc(a653sched_priv_t);
     if ( prv == NULL )
         return -ENOMEM;
 
-    memset(prv, 0, sizeof(*prv));
     ops->sched_data = prv;
 
     prv->schedule[0].dom_handle[0] = '\0';
diff -r e09ebf7a31f5 -r a42af55d50fb xen/common/sched_credit.c
--- a/xen/common/sched_credit.c Tue Oct 04 14:15:26 2011 +0200
+++ b/xen/common/sched_credit.c Tue Oct 04 14:16:32 2011 +0200
@@ -351,10 +351,9 @@
     unsigned long flags;
 
     /* Allocate per-PCPU info */
-    spc = xmalloc(struct csched_pcpu);
+    spc = xzalloc(struct csched_pcpu);
     if ( spc == NULL )
         return NULL;
-    memset(spc, 0, sizeof(*spc));
 
     spin_lock_irqsave(&prv->lock, flags);
 
@@ -649,10 +648,9 @@
     struct csched_vcpu *svc;
 
     /* Allocate per-VCPU info */
-    svc = xmalloc(struct csched_vcpu);
+    svc = xzalloc(struct csched_vcpu);
     if ( svc == NULL )
         return NULL;
-    memset(svc, 0, sizeof(*svc));
 
     INIT_LIST_HEAD(&svc->runq_elem);
     INIT_LIST_HEAD(&svc->active_vcpu_elem);
@@ -837,10 +835,9 @@
 {
     struct csched_dom *sdom;
 
-    sdom = xmalloc(struct csched_dom);
+    sdom = xzalloc(struct csched_dom);
     if ( sdom == NULL )
         return NULL;
-    memset(sdom, 0, sizeof(*sdom));
 
     /* Initialize credit and weight */
     INIT_LIST_HEAD(&sdom->active_vcpu);
@@ -1513,11 +1510,10 @@
 {
     struct csched_private *prv;
 
-    prv = xmalloc(struct csched_private);
+    prv = xzalloc(struct csched_private);
     if ( prv == NULL )
         return -ENOMEM;
 
-    memset(prv, 0, sizeof(*prv));
     ops->sched_data = prv;
     spin_lock_init(&prv->lock);
     INIT_LIST_HEAD(&prv->active_sdom);
diff -r e09ebf7a31f5 -r a42af55d50fb xen/common/sched_credit2.c
--- a/xen/common/sched_credit2.c        Tue Oct 04 14:15:26 2011 +0200
+++ b/xen/common/sched_credit2.c        Tue Oct 04 14:16:32 2011 +0200
@@ -732,10 +732,9 @@
     struct csched_vcpu *svc;
 
     /* Allocate per-VCPU info */
-    svc = xmalloc(struct csched_vcpu);
+    svc = xzalloc(struct csched_vcpu);
     if ( svc == NULL )
         return NULL;
-    memset(svc, 0, sizeof(*svc));
 
     INIT_LIST_HEAD(&svc->rqd_elem);
     INIT_LIST_HEAD(&svc->sdom_elem);
@@ -1437,10 +1436,9 @@
     struct csched_dom *sdom;
     int flags;
 
-    sdom = xmalloc(struct csched_dom);
+    sdom = xzalloc(struct csched_dom);
     if ( sdom == NULL )
         return NULL;
-    memset(sdom, 0, sizeof(*sdom));
 
     /* Initialize credit and weight */
     INIT_LIST_HEAD(&sdom->vcpu);
@@ -2065,10 +2063,9 @@
      * set up basic structures, and a callback when the CPU info is
      * available. */
 
-    prv = xmalloc(struct csched_private);
+    prv = xzalloc(struct csched_private);
     if ( prv == NULL )
         return -ENOMEM;
-    memset(prv, 0, sizeof(*prv));
     ops->sched_data = prv;
     spin_lock_init(&prv->lock);
     INIT_LIST_HEAD(&prv->sdom);
diff -r e09ebf7a31f5 -r a42af55d50fb xen/common/sched_sedf.c
--- a/xen/common/sched_sedf.c   Tue Oct 04 14:15:26 2011 +0200
+++ b/xen/common/sched_sedf.c   Tue Oct 04 14:16:32 2011 +0200
@@ -348,11 +348,10 @@
 {
     struct sedf_vcpu_info *inf;
 
-    inf = xmalloc(struct sedf_vcpu_info);
+    inf = xzalloc(struct sedf_vcpu_info);
     if ( inf == NULL )
         return NULL;
 
-    memset(inf, 0, sizeof(struct sedf_vcpu_info));
     inf->vcpu = v;
 
     /* Every VCPU gets an equal share of extratime by default. */
@@ -387,9 +386,8 @@
 {
     struct sedf_cpu_info *spc;
 
-    spc = xmalloc(struct sedf_cpu_info);
+    spc = xzalloc(struct sedf_cpu_info);
     BUG_ON(spc == NULL);
-    memset(spc, 0, sizeof(*spc));
     INIT_LIST_HEAD(&spc->waitq);
     INIT_LIST_HEAD(&spc->runnableq);
     INIT_LIST_HEAD(&spc->extraq[EXTRA_PEN_Q]);
@@ -415,15 +413,7 @@
 static void *
 sedf_alloc_domdata(const struct scheduler *ops, struct domain *d)
 {
-    void *mem;
-
-    mem = xmalloc(struct sedf_dom_info);
-    if ( mem == NULL )
-        return NULL;
-
-    memset(mem, 0, sizeof(struct sedf_dom_info));
-
-    return mem;
+    return xzalloc(struct sedf_dom_info);
 }
 
 static int sedf_init_domain(const struct scheduler *ops, struct domain *d)
@@ -1333,8 +1323,8 @@
     struct vcpu *p;
     struct domain      *d;
     unsigned int        cpu, nr_cpus = last_cpu(cpu_online_map) + 1;
-    int                *sumw = xmalloc_array(int, nr_cpus);
-    s_time_t           *sumt = xmalloc_array(s_time_t, nr_cpus);
+    int                *sumw = xzalloc_array(int, nr_cpus);
+    s_time_t           *sumt = xzalloc_array(s_time_t, nr_cpus);
 
     if ( !sumw || !sumt )
     {
@@ -1342,8 +1332,6 @@
         xfree(sumw);
         return -ENOMEM;
     }
-    memset(sumw, 0, nr_cpus * sizeof(*sumw));
-    memset(sumt, 0, nr_cpus * sizeof(*sumt));
 
     /* Sum across all weights. */
     rcu_read_lock(&domlist_read_lock);
diff -r e09ebf7a31f5 -r a42af55d50fb xen/common/schedule.c
--- a/xen/common/schedule.c     Tue Oct 04 14:15:26 2011 +0200
+++ b/xen/common/schedule.c     Tue Oct 04 14:16:32 2011 +0200
@@ -233,14 +233,13 @@
     if ( domdata == NULL )
         return -ENOMEM;
 
-    vcpu_priv = xmalloc_array(void *, d->max_vcpus);
+    vcpu_priv = xzalloc_array(void *, d->max_vcpus);
     if ( vcpu_priv == NULL )
     {
         SCHED_OP(c->sched, free_domdata, domdata);
         return -ENOMEM;
     }
 
-    memset(vcpu_priv, 0, d->max_vcpus * sizeof(void *));
     for_each_vcpu ( d, v )
     {
         vcpu_priv[v->vcpu_id] = SCHED_OP(c->sched, alloc_vdata, v, domdata);
diff -r e09ebf7a31f5 -r a42af55d50fb xen/common/wait.c
--- a/xen/common/wait.c Tue Oct 04 14:15:26 2011 +0200
+++ b/xen/common/wait.c Tue Oct 04 14:16:32 2011 +0200
@@ -41,11 +41,10 @@
 {
     struct waitqueue_vcpu *wqv;
 
-    wqv = xmalloc(struct waitqueue_vcpu);
+    wqv = xzalloc(struct waitqueue_vcpu);
     if ( wqv == NULL )
         return -ENOMEM;
 
-    memset(wqv, 0, sizeof(*wqv));
     INIT_LIST_HEAD(&wqv->list);
     wqv->vcpu = v;
 
diff -r e09ebf7a31f5 -r a42af55d50fb xen/common/xenoprof.c
--- a/xen/common/xenoprof.c     Tue Oct 04 14:15:26 2011 +0200
+++ b/xen/common/xenoprof.c     Tue Oct 04 14:16:32 2011 +0200
@@ -193,17 +193,14 @@
     unsigned max_max_samples;
     int i;
 
-    d->xenoprof = xmalloc(struct xenoprof);
-
+    d->xenoprof = xzalloc(struct xenoprof);
     if ( d->xenoprof == NULL )
     {
         printk("alloc_xenoprof_struct(): memory allocation failed\n");
         return -ENOMEM;
     }
 
-    memset(d->xenoprof, 0, sizeof(*d->xenoprof));
-
-    d->xenoprof->vcpu = xmalloc_array(struct xenoprof_vcpu, d->max_vcpus);
+    d->xenoprof->vcpu = xzalloc_array(struct xenoprof_vcpu, d->max_vcpus);
     if ( d->xenoprof->vcpu == NULL )
     {
         xfree(d->xenoprof);
@@ -212,8 +209,6 @@
         return -ENOMEM;
     }
 
-    memset(d->xenoprof->vcpu, 0, d->max_vcpus * sizeof(*d->xenoprof->vcpu));
-
     nvcpu = 0;
     for_each_vcpu ( d, v )
         nvcpu++;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.