LVS
lvs-devel
Google
 
Web LinuxVirtualServer.org

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

To: mcgrof@xxxxxxxxxx
Subject: [PATCH v3 02/14] sysctl: Use ctl_table_header in list_for_each_table_entry
Cc: rds-devel@xxxxxxxxxxxxxx, "David S. Miller" <davem@xxxxxxxxxxxxx>, Florian Westphal <fw@xxxxxxxxx>, willy@xxxxxxxxxxxxx, Jan Karcher <jaka@xxxxxxxxxxxxx>, Wen Gu <guwen@xxxxxxxxxxxxxxxxx>, Simon Horman <horms@xxxxxxxxxxxx>, Tony Lu <tonylu@xxxxxxxxxxxxxxxxx>, linux-wpan@xxxxxxxxxxxxxxx, Matthieu Baerts <matthieu.baerts@xxxxxxxxxxxx>, Christian Borntraeger <borntraeger@xxxxxxxxxxxxx>, mptcp@xxxxxxxxxxxxxxx, Heiko Carstens <hca@xxxxxxxxxxxxx>, Stefan Schmidt <stefan@xxxxxxxxxxxxxxxxxx>, Will Deacon <will@xxxxxxxxxx>, Julian Anastasov <ja@xxxxxx>, netfilter-devel@xxxxxxxxxxxxxxx, Joerg Reuter <jreuter@xxxxxxxx>, linux-kernel@xxxxxxxxxxxxxxx, Alexander Gordeev <agordeev@xxxxxxxxxxxxx>, linux-sctp@xxxxxxxxxxxxxxx, Xin Long <lucien.xin@xxxxxxxxx>, Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>, linux-hams@xxxxxxxxxxxxxxx, Vasily Gorbik <gor@xxxxxxxxxxxxx>, coreteam@xxxxxxxxxxxxx, Ralf Baechle <ralf@xxxxxxxxxxxxxx>, Steffen Klassert <steffen.klassert@xxxxxxxxxxx>, Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>, keescook@xxxxxxxxxxxx, Roopa Prabhu <roopa@xxxxxxxxxx>, David Ahern <dsahern@xxxxxxxxxx>, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, Catalin Marinas <catalin.marinas@xxxxxxx>, Jozsef Kadlecsik <kadlec@xxxxxxxxxxxxx>, Wenjia Zhang <wenjia@xxxxxxxxxxxxx>, josh@xxxxxxxxxxxxxxxx, linux-fsdevel@xxxxxxxxxxxxxxx, Alexander Aring <alex.aring@xxxxxxxxx>, Nikolay Aleksandrov <razor@xxxxxxxxxxxxx>, netdev@xxxxxxxxxxxxxxx, Santosh Shilimkar <santosh.shilimkar@xxxxxxxxxx>, linux-s390@xxxxxxxxxxxxxxx, Sven Schnelle <svens@xxxxxxxxxxxxx>, "D. Wythe" <alibuda@xxxxxxxxxxxxxxxxx>, Eric Dumazet <edumazet@xxxxxxxxxx>, lvs-devel@xxxxxxxxxxxxxxx, linux-rdma@xxxxxxxxxxxxxxx, Paolo Abeni <pabeni@xxxxxxxxxx>, Iurii Zaikin <yzaikin@xxxxxxxxxx>, Marcelo Ricardo Leitner <marcelo.leitner@xxxxxxxxx>, bridge@xxxxxxxxxxxxxxxxxxxxxxxxxx, Karsten Graul <kgraul@xxxxxxxxxxxxx>, Mat Martineau <martineau@xxxxxxxxxx>, Miquel Raynal <miquel.raynal@xxxxxxxxxxx>, Jakub Kicinski <kuba@xxxxxxxxxx>, Joel Granados <j.granados@xxxxxxxxxxx>
From: Joel Granados <joel.granados@xxxxxxxxx>
Date: Wed, 9 Aug 2023 12:49:54 +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>