From: Joel Granados <joel.granados@gmail.com>
To: mcgrof@kernel.org
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Iurii Zaikin <yzaikin@google.com>,
Jozsef Kadlecsik <kadlec@netfilter.org>,
Sven Schnelle <svens@linux.ibm.com>,
Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
Steffen Klassert <steffen.klassert@secunet.com>,
Kees Cook <keescook@chromium.org>,
"D. Wythe" <alibuda@linux.alibaba.com>,
mptcp@lists.linux.dev, Jakub Kicinski <kuba@kernel.org>,
Vasily Gorbik <gor@linux.ibm.com>,
Paolo Abeni <pabeni@redhat.com>,
coreteam@netfilter.org, Jan Karcher <jaka@linux.ibm.com>,
Alexander Aring <alex.aring@gmail.com>,
Will Deacon <will@kernel.org>,
Stefan Schmidt <stefan@datenfreihafen.org>,
Matthieu Baerts <matthieu.baerts@tessares.net>,
bridge@lists.linux-foundation.org,
linux-arm-kernel@lists.infradead.org,
Joerg Reuter <jreuter@yaina.de>, Julian Anastasov <ja@ssi.bg>,
David Ahern <dsahern@kernel.org>,
netfilter-devel@vger.ker
Subject: [PATCH v2 01/14] sysctl: Prefer ctl_table_header in proc_sysctl
Date: Mon, 31 Jul 2023 09:17:15 +0200 [thread overview]
Message-ID: <20230731071728.3493794-2-j.granados@samsung.com> (raw)
In-Reply-To: <20230731071728.3493794-1-j.granados@samsung.com>
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@samsung.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
next prev parent reply other threads:[~2023-07-31 7:17 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-31 7:17 [PATCH v2 00/14] sysctl: Add a size argument to register functions in sysctl Joel Granados
2023-07-31 7:17 ` Joel Granados [this message]
2023-07-31 7:17 ` [PATCH v2 02/14] sysctl: Use ctl_table_header in list_for_each_table_entry Joel Granados
2023-07-31 7:17 ` [PATCH v2 03/14] sysctl: Add ctl_table_size to ctl_table_header Joel Granados
[not found] ` <20230731071728.3493794-4-j.granados-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2023-07-31 18:30 ` Simon Horman
2023-07-31 19:07 ` Simon Horman
2023-08-01 10:03 ` Joel Granados
2023-07-31 7:17 ` [PATCH v2 04/14] sysctl: Add size argument to init_header Joel Granados
2023-07-31 7:17 ` [PATCH v2 05/14] sysctl: Add a size arg to __register_sysctl_table Joel Granados
2023-07-31 7:17 ` [PATCH v2 06/14] sysctl: Add size to register_sysctl Joel Granados
2023-07-31 7:17 ` [PATCH v2 07/14] sysctl: Add size arg to __register_sysctl_init Joel Granados
2023-07-31 7:17 ` [PATCH v2 08/14] sysctl: Add size to register_net_sysctl function Joel Granados
2023-07-31 7:17 ` [PATCH v2 09/14] ax.25: Update to register_net_sysctl_sz Joel Granados
[not found] ` <20230731071728.3493794-1-j.granados-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2023-07-31 7:17 ` [PATCH v2 10/14] netfilter: " Joel Granados
2023-08-01 6:11 ` Julian Anastasov
2023-07-31 7:17 ` [PATCH v2 11/14] networking: " Joel Granados
2023-08-08 11:20 ` Przemek Kitszel
2023-08-08 14:24 ` Joel Granados
2023-08-08 15:23 ` Joel Granados
2023-07-31 7:17 ` [PATCH v2 12/14] vrf: " Joel Granados
2023-07-31 7:17 ` [PATCH v2 13/14] sysctl: SIZE_MAX->ARRAY_SIZE in register_net_sysctl Joel Granados
2023-07-31 7:17 ` [PATCH v2 14/14] sysctl: Use ctl_table_size as stopping criteria for list macro Joel Granados
2023-07-31 20:50 ` [PATCH v2 00/14] sysctl: Add a size argument to register functions in sysctl Luis Chamberlain
2023-08-01 10:01 ` Joel Granados
2023-07-31 21:36 ` Luis Chamberlain
2023-08-01 9:35 ` Joel Granados
2023-08-07 21:44 ` Luis Chamberlain
2023-08-07 23:00 ` Chris Maness
2023-08-07 23:43 ` Luis Chamberlain
2023-08-08 2:50 ` Chris Maness
2023-08-08 3:00 ` Luis Chamberlain
2023-08-08 3:07 ` Chris Maness
2023-08-08 13:59 ` Joel Granados
2023-08-08 13:58 ` Joel Granados
2023-08-08 2:09 ` Jakub Kicinski
2023-08-08 2:34 ` Luis Chamberlain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230731071728.3493794-2-j.granados@samsung.com \
--to=joel.granados@gmail.com \
--cc=alex.aring@gmail.com \
--cc=alibuda@linux.alibaba.com \
--cc=bridge@lists.linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=coreteam@netfilter.org \
--cc=dsahern@kernel.org \
--cc=gor@linux.ibm.com \
--cc=ja@ssi.bg \
--cc=jaka@linux.ibm.com \
--cc=jreuter@yaina.de \
--cc=kadlec@netfilter.org \
--cc=keescook@chromium.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=marcelo.leitner@gmail.com \
--cc=matthieu.baerts@tessares.net \
--cc=mcgrof@kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=netfilter-devel@vger.ker \
--cc=pabeni@redhat.com \
--cc=stefan@datenfreihafen.org \
--cc=steffen.klassert@secunet.com \
--cc=svens@linux.ibm.com \
--cc=will@kernel.org \
--cc=yzaikin@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).