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

[Xen-devel] [PATCH 2/4] flask: use xzalloc()



Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/xen/xsm/flask/avc.c
+++ b/xen/xsm/flask/avc.c
@@ -360,11 +360,10 @@ static struct avc_node *avc_alloc_node(v
 {
     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);
--- a/xen/xsm/flask/hooks.c
+++ b/xen/xsm/flask/hooks.c
@@ -132,13 +132,10 @@ static int flask_domain_alloc_security(s
 {
     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(s
 {
     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;
--- a/xen/xsm/flask/ss/avtab.c
+++ b/xen/xsm/flask/ss/avtab.c
@@ -38,11 +38,10 @@ static struct avtab_node* avtab_insert_n
     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 )
--- 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, s
     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,
         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 policyd
         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, v
 
     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;
--- a/xen/xsm/flask/ss/ebitmap.c
+++ b/xen/xsm/flask/ss/ebitmap.c
@@ -50,13 +50,12 @@ int ebitmap_cpy(struct ebitmap *dst, str
     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, u
     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
 
         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
                 rc = -ENOMEM;
                 goto bad;
             }
-            memset(tmp, 0, sizeof(*tmp));
             /* round down */
             tmp->startbit = startbit - (startbit % EBITMAP_SIZE);
             if ( n )
--- a/xen/xsm/flask/ss/hashtab.c
+++ b/xen/xsm/flask/ss/hashtab.c
@@ -16,28 +16,21 @@ struct hashtab *hashtab_create(u32 (*has
             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, vo
     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 )
--- 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,
     __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 *
     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 const
     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 const
         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
     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,
     __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,
     __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,
     __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,
     __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, 
     __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, vo
     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, vo
     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, vo
         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, vo
         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
--- 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, 
     }
     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, 
             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 **
         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, uns
     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;


Attachment: flask-xzalloc.patch
Description: Text document

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

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