Commit fba472bb authored by Ondrej Mosnacek's avatar Ondrej Mosnacek Committed by Paul Moore

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: default avatarOndrej Mosnacek <omosnace@redhat.com>
Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
parent 6efb943b
...@@ -628,7 +628,8 @@ static int cond_dup_av_list(struct cond_av_list *new, ...@@ -628,7 +628,8 @@ static int cond_dup_av_list(struct cond_av_list *new,
static int duplicate_policydb_cond_list(struct policydb *newp, static int duplicate_policydb_cond_list(struct policydb *newp,
struct policydb *origp) struct policydb *origp)
{ {
int rc, i, j; int rc;
u32 i;
rc = avtab_alloc_dup(&newp->te_cond_avtab, &origp->te_cond_avtab); rc = avtab_alloc_dup(&newp->te_cond_avtab, &origp->te_cond_avtab);
if (rc) if (rc)
...@@ -648,12 +649,12 @@ static int duplicate_policydb_cond_list(struct policydb *newp, ...@@ -648,12 +649,12 @@ static int duplicate_policydb_cond_list(struct policydb *newp,
newp->cond_list_len++; newp->cond_list_len++;
newn->cur_state = orign->cur_state; newn->cur_state = orign->cur_state;
newn->expr.nodes = kcalloc(orign->expr.len, newn->expr.nodes = kmemdup(orign->expr.nodes,
sizeof(*newn->expr.nodes), GFP_KERNEL); orign->expr.len * sizeof(*orign->expr.nodes),
GFP_KERNEL);
if (!newn->expr.nodes) if (!newn->expr.nodes)
goto error; goto error;
for (j = 0; j < orign->expr.len; j++)
newn->expr.nodes[j] = orign->expr.nodes[j];
newn->expr.len = orign->expr.len; newn->expr.len = orign->expr.len;
rc = cond_dup_av_list(&newn->true_list, &orign->true_list, rc = cond_dup_av_list(&newn->true_list, &orign->true_list,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment