diff options
author | Markus Elfring <elfring@users.sourceforge.net> | 2017-04-04 04:20:46 -0400 |
---|---|---|
committer | Paul Moore <paul@paul-moore.com> | 2017-05-23 10:23:12 -0400 |
commit | 62934ffb9e5f9a904c83f571590631b766d68d12 (patch) | |
tree | c2b79b000a9e214d48df8e3cbf6844eb6fdb831f /security/selinux | |
parent | a79be238600d1a0319a77b080b762d03c1d253ca (diff) |
selinux: Return directly after a failed memory allocation in policydb_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>
Diffstat (limited to 'security/selinux')
-rw-r--r-- | security/selinux/ss/policydb.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index 0080122760ad..87d645d3a39f 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c | |||
@@ -538,34 +538,30 @@ static int policydb_index(struct policydb *p) | |||
538 | symtab_hash_eval(p->symtab); | 538 | symtab_hash_eval(p->symtab); |
539 | #endif | 539 | #endif |
540 | 540 | ||
541 | rc = -ENOMEM; | ||
542 | p->class_val_to_struct = kcalloc(p->p_classes.nprim, | 541 | p->class_val_to_struct = kcalloc(p->p_classes.nprim, |
543 | sizeof(*p->class_val_to_struct), | 542 | sizeof(*p->class_val_to_struct), |
544 | GFP_KERNEL); | 543 | GFP_KERNEL); |
545 | if (!p->class_val_to_struct) | 544 | if (!p->class_val_to_struct) |
546 | goto out; | 545 | return -ENOMEM; |
547 | 546 | ||
548 | rc = -ENOMEM; | ||
549 | p->role_val_to_struct = kcalloc(p->p_roles.nprim, | 547 | p->role_val_to_struct = kcalloc(p->p_roles.nprim, |
550 | sizeof(*p->role_val_to_struct), | 548 | sizeof(*p->role_val_to_struct), |
551 | GFP_KERNEL); | 549 | GFP_KERNEL); |
552 | if (!p->role_val_to_struct) | 550 | if (!p->role_val_to_struct) |
553 | goto out; | 551 | return -ENOMEM; |
554 | 552 | ||
555 | rc = -ENOMEM; | ||
556 | p->user_val_to_struct = kcalloc(p->p_users.nprim, | 553 | p->user_val_to_struct = kcalloc(p->p_users.nprim, |
557 | sizeof(*p->user_val_to_struct), | 554 | sizeof(*p->user_val_to_struct), |
558 | GFP_KERNEL); | 555 | GFP_KERNEL); |
559 | if (!p->user_val_to_struct) | 556 | if (!p->user_val_to_struct) |
560 | goto out; | 557 | return -ENOMEM; |
561 | 558 | ||
562 | /* Yes, I want the sizeof the pointer, not the structure */ | 559 | /* Yes, I want the sizeof the pointer, not the structure */ |
563 | rc = -ENOMEM; | ||
564 | p->type_val_to_struct_array = flex_array_alloc(sizeof(struct type_datum *), | 560 | p->type_val_to_struct_array = flex_array_alloc(sizeof(struct type_datum *), |
565 | p->p_types.nprim, | 561 | p->p_types.nprim, |
566 | GFP_KERNEL | __GFP_ZERO); | 562 | GFP_KERNEL | __GFP_ZERO); |
567 | if (!p->type_val_to_struct_array) | 563 | if (!p->type_val_to_struct_array) |
568 | goto out; | 564 | return -ENOMEM; |
569 | 565 | ||
570 | rc = flex_array_prealloc(p->type_val_to_struct_array, 0, | 566 | rc = flex_array_prealloc(p->type_val_to_struct_array, 0, |
571 | p->p_types.nprim, GFP_KERNEL | __GFP_ZERO); | 567 | p->p_types.nprim, GFP_KERNEL | __GFP_ZERO); |
@@ -577,12 +573,11 @@ static int policydb_index(struct policydb *p) | |||
577 | goto out; | 573 | goto out; |
578 | 574 | ||
579 | for (i = 0; i < SYM_NUM; i++) { | 575 | for (i = 0; i < SYM_NUM; i++) { |
580 | rc = -ENOMEM; | ||
581 | p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *), | 576 | p->sym_val_to_name[i] = flex_array_alloc(sizeof(char *), |
582 | p->symtab[i].nprim, | 577 | p->symtab[i].nprim, |
583 | GFP_KERNEL | __GFP_ZERO); | 578 | GFP_KERNEL | __GFP_ZERO); |
584 | if (!p->sym_val_to_name[i]) | 579 | if (!p->sym_val_to_name[i]) |
585 | goto out; | 580 | return -ENOMEM; |
586 | 581 | ||
587 | rc = flex_array_prealloc(p->sym_val_to_name[i], | 582 | rc = flex_array_prealloc(p->sym_val_to_name[i], |
588 | 0, p->symtab[i].nprim, | 583 | 0, p->symtab[i].nprim, |