audit: cull redundancy in audit_rule_change

Re-factor audit_rule_change() to reduce the amount of code redundancy and
simplify the logic.

Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
Signed-off-by: Eric Paris <eparis@redhat.com>
This commit is contained in:
Richard Guy Briggs
2014-10-02 22:05:19 -04:00
committed by Eric Paris
parent 739c95038e
commit e85322d21c

View File

@@ -1064,31 +1064,27 @@ int audit_rule_change(int type, __u32 portid, int seq, void *data,
int err = 0; int err = 0;
struct audit_entry *entry; struct audit_entry *entry;
entry = audit_data_to_entry(data, datasz);
if (IS_ERR(entry))
return PTR_ERR(entry);
switch (type) { switch (type) {
case AUDIT_ADD_RULE: case AUDIT_ADD_RULE:
entry = audit_data_to_entry(data, datasz);
if (IS_ERR(entry))
return PTR_ERR(entry);
err = audit_add_rule(entry); err = audit_add_rule(entry);
audit_log_rule_change("add_rule", &entry->rule, !err); audit_log_rule_change("add_rule", &entry->rule, !err);
if (err)
audit_free_rule(entry);
break; break;
case AUDIT_DEL_RULE: case AUDIT_DEL_RULE:
entry = audit_data_to_entry(data, datasz);
if (IS_ERR(entry))
return PTR_ERR(entry);
err = audit_del_rule(entry); err = audit_del_rule(entry);
audit_log_rule_change("remove_rule", &entry->rule, !err); audit_log_rule_change("remove_rule", &entry->rule, !err);
audit_free_rule(entry);
break; break;
default: default:
err = -EINVAL; err = -EINVAL;
WARN_ON(1); WARN_ON(1);
} }
if (err || type == AUDIT_DEL_RULE)
audit_free_rule(entry);
return err; return err;
} }