SELinux: merge policydb_index_classes and policydb_index_others

We duplicate functionality in policydb_index_classes() and
policydb_index_others().  This patch merges those functions just to make it
clear there is nothing special happening here.

Signed-off-by: Eric Paris <eparis@redhat.com>
This commit is contained in:
Eric Paris 2010-11-29 15:47:09 -05:00
parent ac76c05bec
commit 1d9bc6dc5b
1 changed files with 10 additions and 59 deletions

View File

@ -411,58 +411,6 @@ static int (*index_f[SYM_NUM]) (void *key, void *datum, void *datap) =
cat_index, cat_index,
}; };
/*
* Define the common val_to_name array and the class
* val_to_name and val_to_struct arrays in a policy
* database structure.
*
* Caller must clean up upon failure.
*/
static int policydb_index_classes(struct policydb *p)
{
int rc;
rc = -ENOMEM;
p->sym_val_to_name[SYM_COMMONS] = flex_array_alloc(sizeof(char *),
p->p_commons.nprim,
GFP_KERNEL | __GFP_ZERO);
if (!p->sym_val_to_name[SYM_COMMONS])
goto out;
rc = flex_array_prealloc(p->sym_val_to_name[SYM_COMMONS],
0, p->p_commons.nprim - 1,
GFP_KERNEL | __GFP_ZERO);
if (rc)
goto out;
rc = hashtab_map(p->p_commons.table, common_index, p);
if (rc)
goto out;
rc = -ENOMEM;
p->class_val_to_struct =
kmalloc(p->p_classes.nprim * sizeof(*(p->class_val_to_struct)), GFP_KERNEL);
if (!p->class_val_to_struct)
goto out;
rc = -ENOMEM;
p->sym_val_to_name[SYM_CLASSES] = flex_array_alloc(sizeof(char *),
p->p_classes.nprim,
GFP_KERNEL | __GFP_ZERO);
if (!p->sym_val_to_name[SYM_CLASSES])
goto out;
rc = flex_array_prealloc(p->sym_val_to_name[SYM_CLASSES],
0, p->p_classes.nprim - 1,
GFP_KERNEL | __GFP_ZERO);
if (rc)
goto out;
rc = hashtab_map(p->p_classes.table, class_index, p);
out:
return rc;
}
#ifdef DEBUG_HASHES #ifdef DEBUG_HASHES
static void symtab_hash_eval(struct symtab *s) static void symtab_hash_eval(struct symtab *s)
{ {
@ -500,7 +448,7 @@ static inline void rangetr_hash_eval(struct hashtab *h)
* *
* Caller must clean up on failure. * Caller must clean up on failure.
*/ */
static int policydb_index_others(struct policydb *p) static int policydb_index(struct policydb *p)
{ {
int i, rc; int i, rc;
@ -519,6 +467,13 @@ static int policydb_index_others(struct policydb *p)
symtab_hash_eval(p->symtab); symtab_hash_eval(p->symtab);
#endif #endif
rc = -ENOMEM;
p->class_val_to_struct =
kmalloc(p->p_classes.nprim * sizeof(*(p->class_val_to_struct)),
GFP_KERNEL);
if (!p->class_val_to_struct)
goto out;
rc = -ENOMEM; rc = -ENOMEM;
p->role_val_to_struct = p->role_val_to_struct =
kmalloc(p->p_roles.nprim * sizeof(*(p->role_val_to_struct)), kmalloc(p->p_roles.nprim * sizeof(*(p->role_val_to_struct)),
@ -550,7 +505,7 @@ static int policydb_index_others(struct policydb *p)
if (cond_init_bool_indexes(p)) if (cond_init_bool_indexes(p))
goto out; goto out;
for (i = SYM_ROLES; i < SYM_NUM; i++) { for (i = 0; i < SYM_NUM; i++) {
rc = -ENOMEM; rc = -ENOMEM;
p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *), p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *),
p->symtab[i].nprim, p->symtab[i].nprim,
@ -2296,11 +2251,7 @@ int policydb_read(struct policydb *p, void *fp)
lra = ra; lra = ra;
} }
rc = policydb_index_classes(p); rc = policydb_index(p);
if (rc)
goto bad;
rc = policydb_index_others(p);
if (rc) if (rc)
goto bad; goto bad;