Skip to content

Commit

Permalink
selinux: Return directly after a failed memory allocation in policydb…
Browse files Browse the repository at this point in the history
…_index()

Replace five goto statements (and previous variable assignments) by
direct returns after a memory allocation failure in this function.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Signed-off-by: Paul Moore <paul@paul-moore.com>
  • Loading branch information
Markus Elfring authored and Paul Moore committed May 23, 2017
1 parent a79be23 commit 62934ff
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions security/selinux/ss/policydb.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,34 +538,30 @@ static int policydb_index(struct policydb *p)
symtab_hash_eval(p->symtab);
#endif

rc = -ENOMEM;
p->class_val_to_struct = kcalloc(p->p_classes.nprim,
sizeof(*p->class_val_to_struct),
GFP_KERNEL);
if (!p->class_val_to_struct)
goto out;
return -ENOMEM;

rc = -ENOMEM;
p->role_val_to_struct = kcalloc(p->p_roles.nprim,
sizeof(*p->role_val_to_struct),
GFP_KERNEL);
if (!p->role_val_to_struct)
goto out;
return -ENOMEM;

rc = -ENOMEM;
p->user_val_to_struct = kcalloc(p->p_users.nprim,
sizeof(*p->user_val_to_struct),
GFP_KERNEL);
if (!p->user_val_to_struct)
goto out;
return -ENOMEM;

/* Yes, I want the sizeof the pointer, not the structure */
rc = -ENOMEM;
p->type_val_to_struct_array = flex_array_alloc(sizeof(struct type_datum *),
p->p_types.nprim,
GFP_KERNEL | __GFP_ZERO);
if (!p->type_val_to_struct_array)
goto out;
return -ENOMEM;

rc = flex_array_prealloc(p->type_val_to_struct_array, 0,
p->p_types.nprim, GFP_KERNEL | __GFP_ZERO);
Expand All @@ -577,12 +573,11 @@ static int policydb_index(struct policydb *p)
goto out;

for (i = 0; i < SYM_NUM; i++) {
rc = -ENOMEM;
p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *),
p->symtab[i].nprim,
GFP_KERNEL | __GFP_ZERO);
if (!p->sym_val_to_name[i])
goto out;
return -ENOMEM;

rc = flex_array_prealloc(p->sym_val_to_name[i],
0, p->symtab[i].nprim,
Expand Down

0 comments on commit 62934ff

Please sign in to comment.