audit: cull redundancy in audit_rule_change
authorRichard Guy Briggs <rgb@redhat.com>
Fri, 3 Oct 2014 02:05:19 +0000 (22:05 -0400)
committerEric Paris <eparis@redhat.com>
Fri, 10 Oct 2014 19:07:58 +0000 (15:07 -0400)
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>
kernel/auditfilter.c

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