]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
flask: use xzalloc()
authorJan Beulich <jbeulich@suse.com>
Fri, 28 Feb 2014 16:12:13 +0000 (17:12 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 28 Feb 2014 16:12:13 +0000 (17:12 +0100)
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
xen/xsm/flask/avc.c
xen/xsm/flask/hooks.c
xen/xsm/flask/ss/avtab.c
xen/xsm/flask/ss/conditional.c
xen/xsm/flask/ss/ebitmap.c
xen/xsm/flask/ss/hashtab.c
xen/xsm/flask/ss/policydb.c
xen/xsm/flask/ss/services.c

index 7fede00fc7400edefab711f55a535e0925a0fa8b..a27cf7d1fb66e8bf087a926e07662366f8abf23e 100644 (file)
@@ -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);
index 717dcf00338efb391fa959182976f075ea944f6f..96276ac332bb9408c1b5800bb5a5096f9a98f1db 100644 (file)
@@ -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;
index 47912e94802f7987ef56eebbc1cb9efac520c23c..bfc91c8b0c2c05224dade1467085179c3857a477 100644 (file)
@@ -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 )
index 123d839eb2327ab7109fd4b1dd90ec3dd7e52533..098ddc027d85788d9f5b09839a89f56fbd3f4542 100644 (file)
@@ -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;
index 61f38d89d2bbf6d56e41f0c007a36f75b6eddaaf..bb3ec8e7c96b6b14f5eb8d59e7129147b2c6f0de 100644 (file)
@@ -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 )
index 5be7a8805d6f78f4c7d6aac915d842332985b79d..f35c0dcea08c879cb59544e99094191b6cd261f7 100644 (file)
@@ -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 )
index bdec4ac264e73fcb2335a6a3da1208d5f38aec61..a2aac03aff3a6d46b7043e7ae202e98e859afc28 100644 (file)
@@ -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
index 60673175b77f28e0726e2a8002f6c201b3148f03..4b9c46e11c7fb475127f43a5c006512bd83282ea 100644 (file)
@@ -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;