Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selinux: simplify duplicate_policydb_cond_list() by using kmemdup()

We can do the allocation + copying of expr.nodes in one go using
kmemdup().

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>

authored by

Ondrej Mosnacek and committed by
Paul Moore
fba472bb 6efb943b

+6 -5
+6 -5
security/selinux/ss/conditional.c
··· 628 628 static int duplicate_policydb_cond_list(struct policydb *newp, 629 629 struct policydb *origp) 630 630 { 631 - int rc, i, j; 631 + int rc; 632 + u32 i; 632 633 633 634 rc = avtab_alloc_dup(&newp->te_cond_avtab, &origp->te_cond_avtab); 634 635 if (rc) ··· 649 648 newp->cond_list_len++; 650 649 651 650 newn->cur_state = orign->cur_state; 652 - newn->expr.nodes = kcalloc(orign->expr.len, 653 - sizeof(*newn->expr.nodes), GFP_KERNEL); 651 + newn->expr.nodes = kmemdup(orign->expr.nodes, 652 + orign->expr.len * sizeof(*orign->expr.nodes), 653 + GFP_KERNEL); 654 654 if (!newn->expr.nodes) 655 655 goto error; 656 - for (j = 0; j < orign->expr.len; j++) 657 - newn->expr.nodes[j] = orign->expr.nodes[j]; 656 + 658 657 newn->expr.len = orign->expr.len; 659 658 660 659 rc = cond_dup_av_list(&newn->true_list, &orign->true_list,