diff options
author | Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> | 2010-02-07 06:23:59 -0500 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2010-02-11 01:09:45 -0500 |
commit | ca0b7df3374c5566468c17f26fa2dfd3fe3c6a37 (patch) | |
tree | 39fb8dfd34a84b928d18523da5dcebc5b25cb634 /security/tomoyo/common.c | |
parent | 8007f10259d04f37044c2c731bf9ccdd9161d825 (diff) |
TOMOYO: Reduce lines by using common path for addition and deletion.
Since the codes for adding an entry and removing an entry are similar, we can
save some lines by using "if (is_delete) { ... } else { ... }" branches.
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security/tomoyo/common.c')
-rw-r--r-- | security/tomoyo/common.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c index ae3ed7313ee0..a53ee059da48 100644 --- a/security/tomoyo/common.c +++ b/security/tomoyo/common.c | |||
@@ -1103,10 +1103,10 @@ static LIST_HEAD(tomoyo_policy_manager_list); | |||
1103 | static int tomoyo_update_manager_entry(const char *manager, | 1103 | static int tomoyo_update_manager_entry(const char *manager, |
1104 | const bool is_delete) | 1104 | const bool is_delete) |
1105 | { | 1105 | { |
1106 | struct tomoyo_policy_manager_entry *new_entry; | 1106 | struct tomoyo_policy_manager_entry *entry = NULL; |
1107 | struct tomoyo_policy_manager_entry *ptr; | 1107 | struct tomoyo_policy_manager_entry *ptr; |
1108 | const struct tomoyo_path_info *saved_manager; | 1108 | const struct tomoyo_path_info *saved_manager; |
1109 | int error = -ENOMEM; | 1109 | int error = is_delete ? -ENOENT : -ENOMEM; |
1110 | bool is_domain = false; | 1110 | bool is_domain = false; |
1111 | 1111 | ||
1112 | if (tomoyo_is_domain_def(manager)) { | 1112 | if (tomoyo_is_domain_def(manager)) { |
@@ -1120,29 +1120,25 @@ static int tomoyo_update_manager_entry(const char *manager, | |||
1120 | saved_manager = tomoyo_save_name(manager); | 1120 | saved_manager = tomoyo_save_name(manager); |
1121 | if (!saved_manager) | 1121 | if (!saved_manager) |
1122 | return -ENOMEM; | 1122 | return -ENOMEM; |
1123 | new_entry = kmalloc(sizeof(*new_entry), GFP_KERNEL); | 1123 | if (!is_delete) |
1124 | entry = kmalloc(sizeof(*entry), GFP_KERNEL); | ||
1124 | mutex_lock(&tomoyo_policy_lock); | 1125 | mutex_lock(&tomoyo_policy_lock); |
1125 | list_for_each_entry_rcu(ptr, &tomoyo_policy_manager_list, list) { | 1126 | list_for_each_entry_rcu(ptr, &tomoyo_policy_manager_list, list) { |
1126 | if (ptr->manager != saved_manager) | 1127 | if (ptr->manager != saved_manager) |
1127 | continue; | 1128 | continue; |
1128 | ptr->is_deleted = is_delete; | 1129 | ptr->is_deleted = is_delete; |
1129 | error = 0; | 1130 | error = 0; |
1130 | goto out; | 1131 | break; |
1131 | } | 1132 | } |
1132 | if (is_delete) { | 1133 | if (!is_delete && error && tomoyo_memory_ok(entry)) { |
1133 | error = -ENOENT; | 1134 | entry->manager = saved_manager; |
1134 | goto out; | 1135 | entry->is_domain = is_domain; |
1136 | list_add_tail_rcu(&entry->list, &tomoyo_policy_manager_list); | ||
1137 | entry = NULL; | ||
1138 | error = 0; | ||
1135 | } | 1139 | } |
1136 | if (!tomoyo_memory_ok(new_entry)) | ||
1137 | goto out; | ||
1138 | new_entry->manager = saved_manager; | ||
1139 | new_entry->is_domain = is_domain; | ||
1140 | list_add_tail_rcu(&new_entry->list, &tomoyo_policy_manager_list); | ||
1141 | new_entry = NULL; | ||
1142 | error = 0; | ||
1143 | out: | ||
1144 | mutex_unlock(&tomoyo_policy_lock); | 1140 | mutex_unlock(&tomoyo_policy_lock); |
1145 | kfree(new_entry); | 1141 | kfree(entry); |
1146 | return error; | 1142 | return error; |
1147 | } | 1143 | } |
1148 | 1144 | ||