Skip to content

Commit c52df19

Browse files
committed
selinux: small cleanups in selinux_audit_rule_init()
A few small tweaks to selinux_audit_rule_init(): - Adjust how we use the @rc variable so we are not doing any extra work in the common/success case. - Related to the above, rework the 'out' jump label so that the success and error paths are different, simplifying both. - Cleanup some of the vertical whitespace while we are making the other changes. Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 4158cb6 commit c52df19

1 file changed

Lines changed: 18 additions & 20 deletions

File tree

security/selinux/ss/services.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3541,38 +3541,38 @@ int selinux_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
35413541
tmprule = kzalloc(sizeof(struct selinux_audit_rule), GFP_KERNEL);
35423542
if (!tmprule)
35433543
return -ENOMEM;
3544-
35453544
context_init(&tmprule->au_ctxt);
35463545

35473546
rcu_read_lock();
35483547
policy = rcu_dereference(state->policy);
35493548
policydb = &policy->policydb;
3550-
35513549
tmprule->au_seqno = policy->latest_granting;
3552-
35533550
switch (field) {
35543551
case AUDIT_SUBJ_USER:
35553552
case AUDIT_OBJ_USER:
3556-
rc = -EINVAL;
35573553
userdatum = symtab_search(&policydb->p_users, rulestr);
3558-
if (!userdatum)
3559-
goto out;
3554+
if (!userdatum) {
3555+
rc = -EINVAL;
3556+
goto err;
3557+
}
35603558
tmprule->au_ctxt.user = userdatum->value;
35613559
break;
35623560
case AUDIT_SUBJ_ROLE:
35633561
case AUDIT_OBJ_ROLE:
3564-
rc = -EINVAL;
35653562
roledatum = symtab_search(&policydb->p_roles, rulestr);
3566-
if (!roledatum)
3567-
goto out;
3563+
if (!roledatum) {
3564+
rc = -EINVAL;
3565+
goto err;
3566+
}
35683567
tmprule->au_ctxt.role = roledatum->value;
35693568
break;
35703569
case AUDIT_SUBJ_TYPE:
35713570
case AUDIT_OBJ_TYPE:
3572-
rc = -EINVAL;
35733571
typedatum = symtab_search(&policydb->p_types, rulestr);
3574-
if (!typedatum)
3575-
goto out;
3572+
if (!typedatum) {
3573+
rc = -EINVAL;
3574+
goto err;
3575+
}
35763576
tmprule->au_ctxt.type = typedatum->value;
35773577
break;
35783578
case AUDIT_SUBJ_SEN:
@@ -3582,20 +3582,18 @@ int selinux_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
35823582
rc = mls_from_string(policydb, rulestr, &tmprule->au_ctxt,
35833583
GFP_ATOMIC);
35843584
if (rc)
3585-
goto out;
3585+
goto err;
35863586
break;
35873587
}
3588-
rc = 0;
3589-
out:
35903588
rcu_read_unlock();
35913589

3592-
if (rc) {
3593-
selinux_audit_rule_free(tmprule);
3594-
tmprule = NULL;
3595-
}
3596-
35973590
*rule = tmprule;
3591+
return 0;
35983592

3593+
err:
3594+
rcu_read_unlock();
3595+
selinux_audit_rule_free(tmprule);
3596+
*rule = NULL;
35993597
return rc;
36003598
}
36013599

0 commit comments

Comments
 (0)