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

[Xen-changelog] [xen master] flask: use xzalloc()



commit 25d81b1a2003efd4b60093a0a83f5b9a28a3b6b8
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Fri Feb 28 17:12:13 2014 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Fri Feb 28 17:12:13 2014 +0100

    flask: use xzalloc()
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Acked-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
---
 xen/xsm/flask/avc.c            |    3 +-
 xen/xsm/flask/hooks.c          |   10 +-------
 xen/xsm/flask/ss/avtab.c       |    5 +--
 xen/xsm/flask/ss/conditional.c |   14 +++--------
 xen/xsm/flask/ss/ebitmap.c     |   11 +++------
 xen/xsm/flask/ss/hashtab.c     |   14 ++---------
 xen/xsm/flask/ss/policydb.c    |   45 +++++++++++++--------------------------
 xen/xsm/flask/ss/services.c    |   17 ++++++--------
 8 files changed, 38 insertions(+), 81 deletions(-)

diff --git a/xen/xsm/flask/avc.c b/xen/xsm/flask/avc.c
index 7fede00..a27cf7d 100644
--- a/xen/xsm/flask/avc.c
+++ b/xen/xsm/flask/avc.c
@@ -360,11 +360,10 @@ static struct avc_node *avc_alloc_node(void)
 {
     struct avc_node *node;
 
-    node = xmalloc(struct avc_node);
+    node = xzalloc(struct avc_node);
     if (!node)
         goto out;
 
-    memset(node, 0, sizeof(*node));
     INIT_RCU_HEAD(&node->rhead);
     INIT_HLIST_NODE(&node->list);
     avc_cache_stats_incr(allocations);
diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c
index 717dcf0..96276ac 100644
--- a/xen/xsm/flask/hooks.c
+++ b/xen/xsm/flask/hooks.c
@@ -132,13 +132,10 @@ static int flask_domain_alloc_security(struct domain *d)
 {
     struct domain_security_struct *dsec;
 
-    dsec = xmalloc(struct domain_security_struct);
-
+    dsec = xzalloc(struct domain_security_struct);
     if ( !dsec )
         return -ENOMEM;
 
-    memset(dsec, 0, sizeof(struct domain_security_struct));
-
     switch ( d->domain_id )
     {
     case DOMID_IDLE:
@@ -294,13 +291,10 @@ static int flask_alloc_security_evtchn(struct evtchn *chn)
 {
     struct evtchn_security_struct *esec;
 
-    esec = xmalloc(struct evtchn_security_struct);
-
+    esec = xzalloc(struct evtchn_security_struct);
     if ( !esec )
         return -ENOMEM;
 
-    memset(esec, 0, sizeof(struct evtchn_security_struct));
-
     esec->sid = SECINITSID_UNLABELED;
 
     chn->ssid = esec;
diff --git a/xen/xsm/flask/ss/avtab.c b/xen/xsm/flask/ss/avtab.c
index 47912e9..bfc91c8 100644
--- a/xen/xsm/flask/ss/avtab.c
+++ b/xen/xsm/flask/ss/avtab.c
@@ -38,11 +38,10 @@ static struct avtab_node* avtab_insert_node(struct avtab 
*h, int hvalue,
     struct avtab_node * prev, struct avtab_node * cur, struct avtab_key *key, 
                                                     struct avtab_datum *datum)
 {
-    struct avtab_node * newnode;
-    newnode = xmalloc(struct avtab_node);
+    struct avtab_node *newnode = xzalloc(struct avtab_node);
+
     if ( newnode == NULL )
         return NULL;
-    memset(newnode, 0, sizeof(struct avtab_node));
     newnode->key = *key;
     newnode->datum = *datum;
     if ( prev )
diff --git a/xen/xsm/flask/ss/conditional.c b/xen/xsm/flask/ss/conditional.c
index 123d839..098ddc0 100644
--- a/xen/xsm/flask/ss/conditional.c
+++ b/xen/xsm/flask/ss/conditional.c
@@ -228,10 +228,9 @@ int cond_read_bool(struct policydb *p, struct hashtab *h, 
void *fp)
     u32 len;
     int rc;
 
-    booldatum = xmalloc(struct cond_bool_datum);
+    booldatum = xzalloc(struct cond_bool_datum);
     if ( !booldatum )
         return -1;
-    memset(booldatum, 0, sizeof(struct cond_bool_datum));
 
     rc = next_entry(buf, fp, sizeof buf);
     if ( rc < 0 )
@@ -343,10 +342,9 @@ static int cond_insertf(struct avtab *a, struct avtab_key 
*k,
         goto err;
     }
 
-    list = xmalloc(struct cond_av_list);
+    list = xzalloc(struct cond_av_list);
     if ( !list )
         goto err;
-    memset(list, 0, sizeof(*list));
 
     list->node = node_ptr;
     if ( !data->head )
@@ -441,12 +439,9 @@ static int cond_read_node(struct policydb *p, struct 
cond_node *node, void *fp)
         if ( rc < 0 )
             goto err;
 
-        expr = xmalloc(struct cond_expr);
+        expr = xzalloc(struct cond_expr);
         if ( !expr )
-        {
             goto err;
-        }
-        memset(expr, 0, sizeof(struct cond_expr));
 
         expr->expr_type = le32_to_cpu(buf[0]);
         expr->bool = le32_to_cpu(buf[1]);
@@ -494,10 +489,9 @@ int cond_read_list(struct policydb *p, void *fp)
 
     for ( i = 0; i < len; i++ )
     {
-        node = xmalloc(struct cond_node);
+        node = xzalloc(struct cond_node);
         if ( !node )
             goto err;
-        memset(node, 0, sizeof(struct cond_node));
 
         if ( cond_read_node(p, node, fp) != 0 )
             goto err;
diff --git a/xen/xsm/flask/ss/ebitmap.c b/xen/xsm/flask/ss/ebitmap.c
index 61f38d8..bb3ec8e 100644
--- a/xen/xsm/flask/ss/ebitmap.c
+++ b/xen/xsm/flask/ss/ebitmap.c
@@ -50,13 +50,12 @@ int ebitmap_cpy(struct ebitmap *dst, struct ebitmap *src)
     prev = NULL;
     while ( n )
     {
-        new = xmalloc(struct ebitmap_node);
+        new = xzalloc(struct ebitmap_node);
         if ( !new )
         {
             ebitmap_destroy(dst);
             return -ENOMEM;
         }
-        memset(new, 0, sizeof(*new));
         new->startbit = n->startbit;
         memcpy(new->maps, n->maps, EBITMAP_SIZE / 8);
         new->next = NULL;
@@ -176,10 +175,9 @@ int ebitmap_set_bit(struct ebitmap *e, unsigned long bit, 
int value)
     if ( !value )
         return 0;
 
-    new = xmalloc(struct ebitmap_node);
+    new = xzalloc(struct ebitmap_node);
     if ( !new )
         return -ENOMEM;
-    memset(new, 0, sizeof(*new));
 
     new->startbit = bit - (bit % EBITMAP_SIZE);
     ebitmap_node_set_bit(new, bit);
@@ -284,8 +282,8 @@ int ebitmap_read(struct ebitmap *e, void *fp)
 
         if ( !n || startbit >= n->startbit + EBITMAP_SIZE )
         {
-            struct ebitmap_node *tmp;
-            tmp = xmalloc(struct ebitmap_node);
+            struct ebitmap_node *tmp = xzalloc(struct ebitmap_node);
+
             if ( !tmp )
             {
                 printk(KERN_ERR
@@ -293,7 +291,6 @@ int ebitmap_read(struct ebitmap *e, void *fp)
                 rc = -ENOMEM;
                 goto bad;
             }
-            memset(tmp, 0, sizeof(*tmp));
             /* round down */
             tmp->startbit = startbit - (startbit % EBITMAP_SIZE);
             if ( n )
diff --git a/xen/xsm/flask/ss/hashtab.c b/xen/xsm/flask/ss/hashtab.c
index 5be7a88..f35c0dc 100644
--- a/xen/xsm/flask/ss/hashtab.c
+++ b/xen/xsm/flask/ss/hashtab.c
@@ -16,28 +16,21 @@ struct hashtab *hashtab_create(u32 (*hash_value)(struct 
hashtab *h,
             int (*keycmp)(struct hashtab *h, const void *key1,
                          const void *key2), u32 size)
 {
-    struct hashtab *p;
-    u32 i;
+    struct hashtab *p = xzalloc(struct hashtab);
 
-    p = xmalloc(struct hashtab);
     if ( p == NULL )
         return p;
 
-    memset(p, 0, sizeof(*p));
     p->size = size;
-    p->nel = 0;
     p->hash_value = hash_value;
     p->keycmp = keycmp;
-    p->htable = xmalloc_array(struct hashtab_node *, size);
+    p->htable = xzalloc_array(struct hashtab_node *, size);
     if ( p->htable == NULL )
     {
         xfree(p);
         return NULL;
     }
 
-    for ( i = 0; i < size; i++ )
-        p->htable[i] = NULL;
-
     return p;
 }
 
@@ -61,10 +54,9 @@ int hashtab_insert(struct hashtab *h, void *key, void *datum)
     if ( cur && (h->keycmp(h, key, cur->key) == 0) )
         return -EEXIST;
 
-    newnode = xmalloc(struct hashtab_node);
+    newnode = xzalloc(struct hashtab_node);
     if ( newnode == NULL )
         return -ENOMEM;
-    memset(newnode, 0, sizeof(*newnode));
     newnode->key = key;
     newnode->datum = datum;
     if ( prev )
diff --git a/xen/xsm/flask/ss/policydb.c b/xen/xsm/flask/ss/policydb.c
index bdec4ac..a2aac03 100644
--- a/xen/xsm/flask/ss/policydb.c
+++ b/xen/xsm/flask/ss/policydb.c
@@ -166,13 +166,12 @@ static int roles_init(struct policydb *p)
     int rc;
     struct role_datum *role;
 
-    role = xmalloc(struct role_datum);
+    role = xzalloc(struct role_datum);
     if ( !role )
     {
         rc = -ENOMEM;
         goto out;
     }
-    memset(role, 0, sizeof(*role));
     role->value = ++p->p_roles.nprim;
     if ( role->value != OBJECT_R_VAL )
     {
@@ -950,13 +949,12 @@ static int perm_read(struct policydb *p, struct hashtab 
*h, void *fp)
     __le32 buf[2];
     u32 len;
 
-    perdatum = xmalloc(struct perm_datum);
+    perdatum = xzalloc(struct perm_datum);
     if ( !perdatum )
     {
         rc = -ENOMEM;
         goto out;
     }
-    memset(perdatum, 0, sizeof(*perdatum));
 
     rc = next_entry(buf, fp, sizeof buf);
     if ( rc < 0 )
@@ -994,13 +992,12 @@ static int common_read(struct policydb *p, struct hashtab 
*h, void *fp)
     u32 len, nel;
     int i, rc;
 
-    comdatum = xmalloc(struct common_datum);
+    comdatum = xzalloc(struct common_datum);
     if ( !comdatum )
     {
         rc = -ENOMEM;
         goto out;
     }
-    memset(comdatum, 0, sizeof(*comdatum));
 
     rc = next_entry(buf, fp, sizeof buf);
     if ( rc < 0 )
@@ -1055,10 +1052,9 @@ static int read_cons_helper(struct constraint_node 
**nodep, int ncons,
     lc = NULL;
     for ( i = 0; i < ncons; i++ )
     {
-        c = xmalloc(struct constraint_node);
+        c = xzalloc(struct constraint_node);
         if ( !c )
             return -ENOMEM;
-        memset(c, 0, sizeof(*c));
 
         if ( lc )
         {
@@ -1078,10 +1074,9 @@ static int read_cons_helper(struct constraint_node 
**nodep, int ncons,
         depth = -1;
         for ( j = 0; j < nexpr; j++ )
         {
-            e = xmalloc(struct constraint_expr);
+            e = xzalloc(struct constraint_expr);
             if ( !e )
                 return -ENOMEM;
-            memset(e, 0, sizeof(*e));
 
             if ( le )
                 le->next = e;
@@ -1142,13 +1137,12 @@ static int class_read(struct policydb *p, struct 
hashtab *h, void *fp)
     u32 len, len2, ncons, nel;
     int i, rc;
 
-    cladatum = xmalloc(struct class_datum);
+    cladatum = xzalloc(struct class_datum);
     if ( !cladatum )
     {
         rc = -ENOMEM;
         goto out;
     }
-    memset(cladatum, 0, sizeof(*cladatum));
 
     rc = next_entry(buf, fp, sizeof(u32)*6);
     if ( rc < 0 )
@@ -1226,13 +1220,12 @@ static int role_read(struct policydb *p, struct hashtab 
*h, void *fp)
     __le32 buf[3];
     u32 len;
 
-    role = xmalloc(struct role_datum);
+    role = xzalloc(struct role_datum);
     if ( !role )
     {
         rc = -ENOMEM;
         goto out;
     }
-    memset(role, 0, sizeof(*role));
 
     if ( p->policyvers >= POLICYDB_VERSION_BOUNDARY )
         rc = next_entry(buf, fp, sizeof(buf[0]) * 3);
@@ -1297,13 +1290,12 @@ static int type_read(struct policydb *p, struct hashtab 
*h, void *fp)
     __le32 buf[4];
     u32 len;
 
-    typdatum = xmalloc(struct type_datum);
+    typdatum = xzalloc(struct type_datum);
     if ( !typdatum )
     {
         rc = -ENOMEM;
         return rc;
     }
-    memset(typdatum, 0, sizeof(*typdatum));
 
     if ( p->policyvers >= POLICYDB_VERSION_BOUNDARY )
         rc = next_entry(buf, fp, sizeof(buf[0]) * 4);
@@ -1391,13 +1383,12 @@ static int user_read(struct policydb *p, struct hashtab 
*h, void *fp)
     __le32 buf[3];
     u32 len;
 
-    usrdatum = xmalloc(struct user_datum);
+    usrdatum = xzalloc(struct user_datum);
     if ( !usrdatum )
     {
         rc = -ENOMEM;
         goto out;
     }
-    memset(usrdatum, 0, sizeof(*usrdatum));
 
     if ( p->policyvers >= POLICYDB_VERSION_BOUNDARY )
         rc = next_entry(buf, fp, sizeof(buf[0]) * 3);
@@ -1455,13 +1446,12 @@ static int sens_read(struct policydb *p, struct hashtab 
*h, void *fp)
     __le32 buf[2];
     u32 len;
 
-    levdatum = xmalloc(struct level_datum);
+    levdatum = xzalloc(struct level_datum);
     if ( !levdatum )
     {
         rc = -ENOMEM;
         goto out;
     }
-    memset(levdatum, 0, sizeof(*levdatum));
 
     rc = next_entry(buf, fp, sizeof buf);
     if ( rc < 0 )
@@ -1511,13 +1501,12 @@ static int cat_read(struct policydb *p, struct hashtab 
*h, void *fp)
     __le32 buf[3];
     u32 len;
 
-    catdatum = xmalloc(struct cat_datum);
+    catdatum = xzalloc(struct cat_datum);
     if ( !catdatum )
     {
         rc = -ENOMEM;
         goto out;
     }
-    memset(catdatum, 0, sizeof(*catdatum));
 
     rc = next_entry(buf, fp, sizeof buf);
     if ( rc < 0 )
@@ -1875,13 +1864,12 @@ int policydb_read(struct policydb *p, void *fp)
     ltr = NULL;
     for ( i = 0; i < nel; i++ )
     {
-        tr = xmalloc(struct role_trans);
+        tr = xzalloc(struct role_trans);
         if ( !tr )
         {
             rc = -ENOMEM;
             goto bad;
         }
-        memset(tr, 0, sizeof(*tr));
         if ( ltr )
             ltr->next = tr;
         else
@@ -1909,13 +1897,12 @@ int policydb_read(struct policydb *p, void *fp)
     lra = NULL;
     for ( i = 0; i < nel; i++ )
     {
-        ra = xmalloc(struct role_allow);
+        ra = xzalloc(struct role_allow);
         if ( !ra )
         {
             rc = -ENOMEM;
             goto bad;
         }
-        memset(ra, 0, sizeof(*ra));
         if ( lra )
             lra->next = ra;
         else
@@ -1951,13 +1938,12 @@ int policydb_read(struct policydb *p, void *fp)
         l = NULL;
         for ( j = 0; j < nel; j++ )
         {
-            c = xmalloc(struct ocontext);
+            c = xzalloc(struct ocontext);
             if ( !c )
             {
                 rc = -ENOMEM;
                 goto bad;
             }
-            memset(c, 0, sizeof(*c));
             if ( l )
                 l->next = c;
             else
@@ -2067,13 +2053,12 @@ int policydb_read(struct policydb *p, void *fp)
         lrt = NULL;
         for ( i = 0; i < nel; i++ )
         {
-            rt = xmalloc(struct range_trans);
+            rt = xzalloc(struct range_trans);
             if ( !rt )
             {
                 rc = -ENOMEM;
                 goto bad;
             }
-            memset(rt, 0, sizeof(*rt));
             if ( lrt )
                 lrt->next = rt;
             else
diff --git a/xen/xsm/flask/ss/services.c b/xen/xsm/flask/ss/services.c
index 6067317..4b9c46e 100644
--- a/xen/xsm/flask/ss/services.c
+++ b/xen/xsm/flask/ss/services.c
@@ -1771,13 +1771,12 @@ int security_get_user_sids(u32 fromsid, char *username, 
u32 **sids, u32 *nel)
     }
     usercon.user = user->value;
 
-    mysids = xmalloc_array(u32, maxnel);
+    mysids = xzalloc_array(u32, maxnel);
     if ( !mysids )
     {
         rc = -ENOMEM;
         goto out_unlock;
     }
-    memset(mysids, 0, maxnel*sizeof(*mysids));
 
     ebitmap_for_each_positive_bit(&user->roles, rnode, i)
     {
@@ -1808,14 +1807,13 @@ int security_get_user_sids(u32 fromsid, char *username, 
u32 **sids, u32 *nel)
             else
             {
                 maxnel += SIDS_NEL;
-                mysids2 = xmalloc_array(u32, maxnel);
+                mysids2 = xzalloc_array(u32, maxnel);
                 if ( !mysids2 )
                 {
                     rc = -ENOMEM;
                     xfree(mysids);
                     goto out_unlock;
                 }
-                memset(mysids2, 0, maxnel*sizeof(*mysids2));
                 memcpy(mysids2, mysids, mynel * sizeof(*mysids2));
                 xfree(mysids);
                 mysids = mysids2;
@@ -1868,14 +1866,14 @@ int security_get_bools(int *len, char ***names, int 
**values, size_t *maxstr)
         goto out;
     }
 
-    if ( names ) {
-        *names = (char**)xmalloc_array(char*, *len);
+    if ( names )
+    {
+        *names = xzalloc_array(char *, *len);
         if ( !*names )
             goto err;
-        memset(*names, 0, sizeof(char*) * *len);
     }
 
-    *values = (int*)xmalloc_array(int, *len);
+    *values = xmalloc_array(int, *len);
     if ( !*values )
         goto err;
 
@@ -2059,9 +2057,8 @@ int security_ocontext_add( u32 ocon, unsigned long low, 
unsigned long high
     struct ocontext *prev;
     struct ocontext *add;
 
-    if ( (add = xmalloc(struct ocontext)) == NULL )
+    if ( (add = xzalloc(struct ocontext)) == NULL )
         return -ENOMEM;
-    memset(add, 0, sizeof(struct ocontext));
     add->sid[0] = sid;
 
     POLICY_WRLOCK;
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
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®.