[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230731071728.3493794-2-j.granados@samsung.com>
Date: Mon, 31 Jul 2023 09:17:15 +0200
From: Joel Granados <joel.granados@...il.com>
To: mcgrof@...nel.org
Cc: Catalin Marinas <catalin.marinas@....com>,
Iurii Zaikin <yzaikin@...gle.com>,
Jozsef Kadlecsik <kadlec@...filter.org>,
Sven Schnelle <svens@...ux.ibm.com>,
Marcelo Ricardo Leitner <marcelo.leitner@...il.com>,
Steffen Klassert <steffen.klassert@...unet.com>,
Kees Cook <keescook@...omium.org>,
"D. Wythe" <alibuda@...ux.alibaba.com>, mptcp@...ts.linux.dev,
Jakub Kicinski <kuba@...nel.org>,
Vasily Gorbik <gor@...ux.ibm.com>,
Paolo Abeni <pabeni@...hat.com>, coreteam@...filter.org,
Jan Karcher <jaka@...ux.ibm.com>,
Alexander Aring <alex.aring@...il.com>,
Will Deacon <will@...nel.org>,
Stefan Schmidt <stefan@...enfreihafen.org>,
Matthieu Baerts <matthieu.baerts@...sares.net>,
bridge@...ts.linux-foundation.org,
linux-arm-kernel@...ts.infradead.org,
Joerg Reuter <jreuter@...na.de>, Julian Anastasov <ja@....bg>,
David Ahern <dsahern@...nel.org>,
netfilter-devel@...r.kernel.org, Wen Gu <guwen@...ux.alibaba.com>,
linux-kernel@...r.kernel.org,
Santosh Shilimkar <santosh.shilimkar@...cle.com>,
linux-wpan@...r.kernel.org, lvs-devel@...r.kernel.org,
Karsten Graul <kgraul@...ux.ibm.com>,
Miquel Raynal <miquel.raynal@...tlin.com>,
Herbert Xu <herbert@...dor.apana.org.au>,
linux-sctp@...r.kernel.org, Tony Lu <tonylu@...ux.alibaba.com>,
Pablo Neira Ayuso <pablo@...filter.org>,
Ralf Baechle <ralf@...ux-mips.org>,
Florian Westphal <fw@...len.de>, willy@...radead.org,
Heiko Carstens <hca@...ux.ibm.com>,
"David S. Miller" <davem@...emloft.net>,
linux-rdma@...r.kernel.org, Roopa Prabhu <roopa@...dia.com>,
Alexander Gordeev <agordeev@...ux.ibm.com>,
Simon Horman <horms@...ge.net.au>,
Mat Martineau <martineau@...nel.org>, josh@...htriplett.org,
Christian Borntraeger <borntraeger@...ux.ibm.com>,
Eric Dumazet <edumazet@...gle.com>, linux-hams@...r.kernel.org,
Wenjia Zhang <wenjia@...ux.ibm.com>,
linux-fsdevel@...r.kernel.org, linux-s390@...r.kernel.org,
Xin Long <lucien.xin@...il.com>,
Nikolay Aleksandrov <razor@...ckwall.org>,
netdev@...r.kernel.org, rds-devel@....oracle.com,
Joel Granados <j.granados@...sung.com>
Subject: [PATCH v2 01/14] 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: Joel Granados <j.granados@...sung.com>
---
fs/proc/proc_sysctl.c | 36 ++++++++++++++++++------------------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 5ea42653126e..94d71446da39 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -1125,11 +1125,11 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table)
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;
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) ||
(entry->proc_handler == proc_dobool) ||
(entry->proc_handler == proc_dointvec) ||
@@ -1159,8 +1159,7 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
return err;
}
-static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
- struct ctl_table_root *link_root)
+static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_header *head)
{
struct ctl_table *link_table, *entry, *link;
struct ctl_table_header *links;
@@ -1170,7 +1169,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
name_bytes = 0;
nr_entries = 0;
- list_for_each_table_entry(entry, table) {
+ list_for_each_table_entry(entry, head->ctl_table) {
nr_entries++;
name_bytes += strlen(entry->procname) + 1;
}
@@ -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 = link_table;
- list_for_each_table_entry(entry, table) {
+ list_for_each_table_entry(entry, head->ctl_table) {
int len = strlen(entry->procname) + 1;
memcpy(link_name, entry->procname, len);
link->procname = link_name;
link->mode = S_IFLNK|S_IRWXUGO;
- link->data = link_root;
+ link->data = head->root;
link_name += len;
link++;
}
@@ -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,
- 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;
/* 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;
- link = find_entry(&head, dir, procname, strlen(procname));
+ link = find_entry(&tmp_head, dir, procname, strlen(procname));
if (!link)
return false;
if (S_ISDIR(link->mode) && S_ISDIR(entry->mode))
@@ -1224,10 +1224,10 @@ static bool get_links(struct ctl_dir *dir,
}
/* 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;
- link = find_entry(&head, dir, procname, strlen(procname));
- head->nreg++;
+ link = find_entry(&tmp_head, dir, procname, strlen(procname));
+ tmp_head->nreg++;
}
return true;
}
@@ -1246,13 +1246,13 @@ static int insert_links(struct ctl_table_header *head)
if (IS_ERR(core_parent))
return 0;
- if (get_links(core_parent, head->ctl_table, head->root))
+ if (get_links(core_parent, head, head->root))
return 0;
core_parent->header.nreg++;
spin_unlock(&sysctl_lock);
- links = new_links(core_parent, head->ctl_table, head->root);
+ links = new_links(core_parent, head);
spin_lock(&sysctl_lock);
err = -ENOMEM;
@@ -1260,7 +1260,7 @@ static int insert_links(struct ctl_table_header *head)
goto out;
err = 0;
- if (get_links(core_parent, head->ctl_table, head->root)) {
+ if (get_links(core_parent, head, head->root)) {
kfree(links);
goto out;
}
@@ -1371,7 +1371,7 @@ struct ctl_table_header *__register_sysctl_table(
node = (struct ctl_node *)(header + 1);
init_header(header, root, set, node, table);
- if (sysctl_check_table(path, table))
+ if (sysctl_check_table(path, header))
goto fail;
spin_lock(&sysctl_lock);
--
2.30.2
Powered by blists - more mailing lists