Commit cc9f7ee0 authored by Joel Granados's avatar Joel Granados Committed by Luis Chamberlain

sysctl: Prefer ctl_table_header in proc_sysctl

This is a preparation commit that replaces ctl_table with
ctl_table_header as the pointer that is passed around in proc_sysctl.c.
This will become necessary in subsequent commits when the size of the
ctl_table array can no longer be calculated by searching for an empty
sentinel (last empty ctl_table element) but will be carried along inside
the ctl_table_header struct.
Signed-off-by: default avatarJoel Granados <j.granados@samsung.com>
Signed-off-by: default avatarLuis Chamberlain <mcgrof@kernel.org>
parent 06c2afb8
...@@ -1125,11 +1125,11 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table) ...@@ -1125,11 +1125,11 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table)
return err; return err;
} }
static int sysctl_check_table(const char *path, struct ctl_table *table) static int sysctl_check_table(const char *path, struct ctl_table_header *header)
{ {
struct ctl_table *entry; struct ctl_table *entry;
int err = 0; int err = 0;
list_for_each_table_entry(entry, table) { list_for_each_table_entry(entry, header->ctl_table) {
if ((entry->proc_handler == proc_dostring) || if ((entry->proc_handler == proc_dostring) ||
(entry->proc_handler == proc_dobool) || (entry->proc_handler == proc_dobool) ||
(entry->proc_handler == proc_dointvec) || (entry->proc_handler == proc_dointvec) ||
...@@ -1159,8 +1159,7 @@ static int sysctl_check_table(const char *path, struct ctl_table *table) ...@@ -1159,8 +1159,7 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
return err; return err;
} }
static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table, static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_header *head)
struct ctl_table_root *link_root)
{ {
struct ctl_table *link_table, *entry, *link; struct ctl_table *link_table, *entry, *link;
struct ctl_table_header *links; struct ctl_table_header *links;
...@@ -1170,7 +1169,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table ...@@ -1170,7 +1169,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
name_bytes = 0; name_bytes = 0;
nr_entries = 0; nr_entries = 0;
list_for_each_table_entry(entry, table) { list_for_each_table_entry(entry, head->ctl_table) {
nr_entries++; nr_entries++;
name_bytes += strlen(entry->procname) + 1; name_bytes += strlen(entry->procname) + 1;
} }
...@@ -1189,12 +1188,12 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table ...@@ -1189,12 +1188,12 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
link_name = (char *)&link_table[nr_entries + 1]; link_name = (char *)&link_table[nr_entries + 1];
link = link_table; link = link_table;
list_for_each_table_entry(entry, table) { list_for_each_table_entry(entry, head->ctl_table) {
int len = strlen(entry->procname) + 1; int len = strlen(entry->procname) + 1;
memcpy(link_name, entry->procname, len); memcpy(link_name, entry->procname, len);
link->procname = link_name; link->procname = link_name;
link->mode = S_IFLNK|S_IRWXUGO; link->mode = S_IFLNK|S_IRWXUGO;
link->data = link_root; link->data = head->root;
link_name += len; link_name += len;
link++; link++;
} }
...@@ -1205,15 +1204,16 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table ...@@ -1205,15 +1204,16 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
} }
static bool get_links(struct ctl_dir *dir, static bool get_links(struct ctl_dir *dir,
struct ctl_table *table, struct ctl_table_root *link_root) struct ctl_table_header *header,
struct ctl_table_root *link_root)
{ {
struct ctl_table_header *head; struct ctl_table_header *tmp_head;
struct ctl_table *entry, *link; struct ctl_table *entry, *link;
/* Are there links available for every entry in table? */ /* Are there links available for every entry in table? */
list_for_each_table_entry(entry, table) { list_for_each_table_entry(entry, header->ctl_table) {
const char *procname = entry->procname; const char *procname = entry->procname;
link = find_entry(&head, dir, procname, strlen(procname)); link = find_entry(&tmp_head, dir, procname, strlen(procname));
if (!link) if (!link)
return false; return false;
if (S_ISDIR(link->mode) && S_ISDIR(entry->mode)) if (S_ISDIR(link->mode) && S_ISDIR(entry->mode))
...@@ -1224,10 +1224,10 @@ static bool get_links(struct ctl_dir *dir, ...@@ -1224,10 +1224,10 @@ static bool get_links(struct ctl_dir *dir,
} }
/* The checks passed. Increase the registration count on the links */ /* The checks passed. Increase the registration count on the links */
list_for_each_table_entry(entry, table) { list_for_each_table_entry(entry, header->ctl_table) {
const char *procname = entry->procname; const char *procname = entry->procname;
link = find_entry(&head, dir, procname, strlen(procname)); link = find_entry(&tmp_head, dir, procname, strlen(procname));
head->nreg++; tmp_head->nreg++;
} }
return true; return true;
} }
...@@ -1246,13 +1246,13 @@ static int insert_links(struct ctl_table_header *head) ...@@ -1246,13 +1246,13 @@ static int insert_links(struct ctl_table_header *head)
if (IS_ERR(core_parent)) if (IS_ERR(core_parent))
return 0; return 0;
if (get_links(core_parent, head->ctl_table, head->root)) if (get_links(core_parent, head, head->root))
return 0; return 0;
core_parent->header.nreg++; core_parent->header.nreg++;
spin_unlock(&sysctl_lock); spin_unlock(&sysctl_lock);
links = new_links(core_parent, head->ctl_table, head->root); links = new_links(core_parent, head);
spin_lock(&sysctl_lock); spin_lock(&sysctl_lock);
err = -ENOMEM; err = -ENOMEM;
...@@ -1260,7 +1260,7 @@ static int insert_links(struct ctl_table_header *head) ...@@ -1260,7 +1260,7 @@ static int insert_links(struct ctl_table_header *head)
goto out; goto out;
err = 0; err = 0;
if (get_links(core_parent, head->ctl_table, head->root)) { if (get_links(core_parent, head, head->root)) {
kfree(links); kfree(links);
goto out; goto out;
} }
...@@ -1371,7 +1371,7 @@ struct ctl_table_header *__register_sysctl_table( ...@@ -1371,7 +1371,7 @@ struct ctl_table_header *__register_sysctl_table(
node = (struct ctl_node *)(header + 1); node = (struct ctl_node *)(header + 1);
init_header(header, root, set, node, table); init_header(header, root, set, node, table);
if (sysctl_check_table(path, table)) if (sysctl_check_table(path, header))
goto fail; goto fail;
spin_lock(&sysctl_lock); spin_lock(&sysctl_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment