aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc/proc_sysctl.c
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2012-01-19 01:57:15 -0500
committerEric W. Biederman <ebiederm@xmission.com>2012-01-24 19:40:30 -0500
commite54012cede6749528899f66a72312522a179d427 (patch)
tree13fe8f0b968da3fcb349e2867d80dfd2e3f5ef9d /fs/proc/proc_sysctl.c
parent60a47a2e823cbe6b609346bffff61a00c0c76470 (diff)
sysctl: Move sysctl_check_dups into insert_header
Simplify the callers of insert_header by removing explicit calls to check for duplicates and instead have insert_header do the work. This makes the code slightly more maintainable by enabling changes to data structures where the insertion of new entries without duplicate suppression is not possible. There is not always a convenient path string where insert_header is called so modify sysctl_check_dups to use sysctl_print_dir when printing the full path when a duplicate is discovered. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Diffstat (limited to 'fs/proc/proc_sysctl.c')
-rw-r--r--fs/proc/proc_sysctl.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index e0d3e7e59cbd..160d5781638e 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -52,6 +52,7 @@ static int sysctl_follow_link(struct ctl_table_header **phead,
52 struct ctl_table **pentry, struct nsproxy *namespaces); 52 struct ctl_table **pentry, struct nsproxy *namespaces);
53static int insert_links(struct ctl_table_header *head); 53static int insert_links(struct ctl_table_header *head);
54static void put_links(struct ctl_table_header *header); 54static void put_links(struct ctl_table_header *header);
55static int sysctl_check_dups(struct ctl_dir *dir, struct ctl_table *table);
55 56
56static void sysctl_print_dir(struct ctl_dir *dir) 57static void sysctl_print_dir(struct ctl_dir *dir)
57{ 58{
@@ -123,6 +124,10 @@ static int insert_header(struct ctl_dir *dir, struct ctl_table_header *header)
123{ 124{
124 int err; 125 int err;
125 126
127 err = sysctl_check_dups(dir, header->ctl_table);
128 if (err)
129 return err;
130
126 dir->header.nreg++; 131 dir->header.nreg++;
127 header->parent = dir; 132 header->parent = dir;
128 err = insert_links(header); 133 err = insert_links(header);
@@ -891,7 +896,7 @@ static int sysctl_follow_link(struct ctl_table_header **phead,
891 return ret; 896 return ret;
892} 897}
893 898
894static int sysctl_check_table_dups(const char *path, struct ctl_table *old, 899static int sysctl_check_table_dups(struct ctl_dir *dir, struct ctl_table *old,
895 struct ctl_table *table) 900 struct ctl_table *table)
896{ 901{
897 struct ctl_table *entry, *test; 902 struct ctl_table *entry, *test;
@@ -900,8 +905,9 @@ static int sysctl_check_table_dups(const char *path, struct ctl_table *old,
900 for (entry = old; entry->procname; entry++) { 905 for (entry = old; entry->procname; entry++) {
901 for (test = table; test->procname; test++) { 906 for (test = table; test->procname; test++) {
902 if (strcmp(entry->procname, test->procname) == 0) { 907 if (strcmp(entry->procname, test->procname) == 0) {
903 printk(KERN_ERR "sysctl duplicate entry: %s/%s\n", 908 printk(KERN_ERR "sysctl duplicate entry: ");
904 path, test->procname); 909 sysctl_print_dir(dir);
910 printk(KERN_CONT "/%s\n", test->procname);
905 error = -EEXIST; 911 error = -EEXIST;
906 } 912 }
907 } 913 }
@@ -909,8 +915,7 @@ static int sysctl_check_table_dups(const char *path, struct ctl_table *old,
909 return error; 915 return error;
910} 916}
911 917
912static int sysctl_check_dups(struct ctl_dir *dir, 918static int sysctl_check_dups(struct ctl_dir *dir, struct ctl_table *table)
913 const char *path, struct ctl_table *table)
914{ 919{
915 struct ctl_table_set *set; 920 struct ctl_table_set *set;
916 struct ctl_table_header *head; 921 struct ctl_table_header *head;
@@ -922,7 +927,7 @@ static int sysctl_check_dups(struct ctl_dir *dir,
922 continue; 927 continue;
923 if (head->parent != dir) 928 if (head->parent != dir)
924 continue; 929 continue;
925 error = sysctl_check_table_dups(path, head->ctl_table, table); 930 error = sysctl_check_table_dups(dir, head->ctl_table, table);
926 } 931 }
927 return error; 932 return error;
928} 933}
@@ -1166,9 +1171,6 @@ struct ctl_table_header *__register_sysctl_table(
1166 } 1171 }
1167 1172
1168 spin_lock(&sysctl_lock); 1173 spin_lock(&sysctl_lock);
1169 if (sysctl_check_dups(dir, path, table))
1170 goto fail_put_dir_locked;
1171
1172 if (insert_header(dir, header)) 1174 if (insert_header(dir, header))
1173 goto fail_put_dir_locked; 1175 goto fail_put_dir_locked;
1174 1176