LVS
lvs-devel
Google
 
Web LinuxVirtualServer.org

[PATCH v2 02/14] sysctl: Use ctl_table_header in list_for_each_table_ent

To: mcgrof@xxxxxxxxxx
Subject: [PATCH v2 02/14] sysctl: Use ctl_table_header in list_for_each_table_entry
Cc: Catalin Marinas <catalin.marinas@xxxxxxx>, Iurii Zaikin <yzaikin@xxxxxxxxxx>, Jozsef Kadlecsik <kadlec@xxxxxxxxxxxxx>, Sven Schnelle <svens@xxxxxxxxxxxxx>, Marcelo Ricardo Leitner <marcelo.leitner@xxxxxxxxx>, Steffen Klassert <steffen.klassert@xxxxxxxxxxx>, Kees Cook <keescook@xxxxxxxxxxxx>, "D. Wythe" <alibuda@xxxxxxxxxxxxxxxxx>, mptcp@xxxxxxxxxxxxxxx, Jakub Kicinski <kuba@xxxxxxxxxx>, Vasily Gorbik <gor@xxxxxxxxxxxxx>, Paolo Abeni <pabeni@xxxxxxxxxx>, coreteam@xxxxxxxxxxxxx, Jan Karcher <jaka@xxxxxxxxxxxxx>, Alexander Aring <alex.aring@xxxxxxxxx>, Will Deacon <will@xxxxxxxxxx>, Stefan Schmidt <stefan@xxxxxxxxxxxxxxxxxx>, Matthieu Baerts <matthieu.baerts@xxxxxxxxxxxx>, bridge@xxxxxxxxxxxxxxxxxxxxxxxxxx, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, Joerg Reuter <jreuter@xxxxxxxx>, Julian Anastasov <ja@xxxxxx>, David Ahern <dsahern@xxxxxxxxxx>, netfilter-devel@xxxxxxxxxxxxxxx, Wen Gu <guwen@xxxxxxxxxxxxxxxxx>, linux-kernel@xxxxxxxxxxxxxxx, Santosh Shilimkar <santosh.shilimkar@xxxxxxxxxx>, linux-wpan@xxxxxxxxxxxxxxx, lvs-devel@xxxxxxxxxxxxxxx, Karsten Graul <kgraul@xxxxxxxxxxxxx>, Miquel Raynal <miquel.raynal@xxxxxxxxxxx>, Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>, linux-sctp@xxxxxxxxxxxxxxx, Tony Lu <tonylu@xxxxxxxxxxxxxxxxx>, Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>, Ralf Baechle <ralf@xxxxxxxxxxxxxx>, Florian Westphal <fw@xxxxxxxxx>, willy@xxxxxxxxxxxxx, Heiko Carstens <hca@xxxxxxxxxxxxx>, "David S. Miller" <davem@xxxxxxxxxxxxx>, linux-rdma@xxxxxxxxxxxxxxx, Roopa Prabhu <roopa@xxxxxxxxxx>, Alexander Gordeev <agordeev@xxxxxxxxxxxxx>, Simon Horman <horms@xxxxxxxxxxxx>, Mat Martineau <martineau@xxxxxxxxxx>, josh@xxxxxxxxxxxxxxxx, Christian Borntraeger <borntraeger@xxxxxxxxxxxxx>, Eric Dumazet <edumazet@xxxxxxxxxx>, linux-hams@xxxxxxxxxxxxxxx, Wenjia Zhang <wenjia@xxxxxxxxxxxxx>, linux-fsdevel@xxxxxxxxxxxxxxx, linux-s390@xxxxxxxxxxxxxxx, Xin Long <lucien.xin@xxxxxxxxx>, Nikolay Aleksandrov <razor@xxxxxxxxxxxxx>, netdev@xxxxxxxxxxxxxxx, rds-devel@xxxxxxxxxxxxxx, Joel Granados <j.granados@xxxxxxxxxxx>
From: Joel Granados <joel.granados@xxxxxxxxx>
Date: Mon, 31 Jul 2023 09:17:16 +0200
We replace the ctl_table with the ctl_table_header pointer in
list_for_each_table_entry which is the macro responsible for traversing
the ctl_table arrays. This is a preparation commit that will make it
easier to add the ctl_table array size (that will be added to
ctl_table_header in subsequent commits) to the already existing loop
logic based on empty ctl_table elements (so called sentinels).

Signed-off-by: Joel Granados <j.granados@xxxxxxxxxxx>
---
 fs/proc/proc_sysctl.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 94d71446da39..884460b0385b 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -19,8 +19,8 @@
 #include <linux/kmemleak.h>
 #include "internal.h"
 
-#define list_for_each_table_entry(entry, table) \
-       for ((entry) = (table); (entry)->procname; (entry)++)
+#define list_for_each_table_entry(entry, header) \
+       for ((entry) = (header->ctl_table); (entry)->procname; (entry)++)
 
 static const struct dentry_operations proc_sys_dentry_operations;
 static const struct file_operations proc_sys_file_operations;
@@ -204,7 +204,7 @@ static void init_header(struct ctl_table_header *head,
        if (node) {
                struct ctl_table *entry;
 
-               list_for_each_table_entry(entry, table) {
+               list_for_each_table_entry(entry, head) {
                        node->header = head;
                        node++;
                }
@@ -215,7 +215,7 @@ static void erase_header(struct ctl_table_header *head)
 {
        struct ctl_table *entry;
 
-       list_for_each_table_entry(entry, head->ctl_table)
+       list_for_each_table_entry(entry, head)
                erase_entry(head, entry);
 }
 
@@ -242,7 +242,7 @@ static int insert_header(struct ctl_dir *dir, struct 
ctl_table_header *header)
        err = insert_links(header);
        if (err)
                goto fail_links;
-       list_for_each_table_entry(entry, header->ctl_table) {
+       list_for_each_table_entry(entry, header) {
                err = insert_entry(header, entry);
                if (err)
                        goto fail;
@@ -1129,7 +1129,7 @@ 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, header->ctl_table) {
+       list_for_each_table_entry(entry, header) {
                if ((entry->proc_handler == proc_dostring) ||
                    (entry->proc_handler == proc_dobool) ||
                    (entry->proc_handler == proc_dointvec) ||
@@ -1169,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, head->ctl_table) {
+       list_for_each_table_entry(entry, head) {
                nr_entries++;
                name_bytes += strlen(entry->procname) + 1;
        }
@@ -1188,7 +1188,7 @@ 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, head->ctl_table) {
+       list_for_each_table_entry(entry, head) {
                int len = strlen(entry->procname) + 1;
                memcpy(link_name, entry->procname, len);
                link->procname = link_name;
@@ -1211,7 +1211,7 @@ static bool get_links(struct ctl_dir *dir,
        struct ctl_table *entry, *link;
 
        /* Are there links available for every entry in table? */
-       list_for_each_table_entry(entry, header->ctl_table) {
+       list_for_each_table_entry(entry, header) {
                const char *procname = entry->procname;
                link = find_entry(&tmp_head, dir, procname, strlen(procname));
                if (!link)
@@ -1224,7 +1224,7 @@ static bool get_links(struct ctl_dir *dir,
        }
 
        /* The checks passed.  Increase the registration count on the links */
-       list_for_each_table_entry(entry, header->ctl_table) {
+       list_for_each_table_entry(entry, header) {
                const char *procname = entry->procname;
                link = find_entry(&tmp_head, dir, procname, strlen(procname));
                tmp_head->nreg++;
@@ -1356,12 +1356,14 @@ struct ctl_table_header *__register_sysctl_table(
 {
        struct ctl_table_root *root = set->dir.header.root;
        struct ctl_table_header *header;
+       struct ctl_table_header h_tmp;
        struct ctl_dir *dir;
        struct ctl_table *entry;
        struct ctl_node *node;
        int nr_entries = 0;
 
-       list_for_each_table_entry(entry, table)
+       h_tmp.ctl_table = table;
+       list_for_each_table_entry(entry, (&h_tmp))
                nr_entries++;
 
        header = kzalloc(sizeof(struct ctl_table_header) +
@@ -1471,7 +1473,7 @@ static void put_links(struct ctl_table_header *header)
        if (IS_ERR(core_parent))
                return;
 
-       list_for_each_table_entry(entry, header->ctl_table) {
+       list_for_each_table_entry(entry, header) {
                struct ctl_table_header *link_head;
                struct ctl_table *link;
                const char *name = entry->procname;
-- 
2.30.2


<Prev in Thread] Current Thread [Next in Thread>