LVS
lvs-devel
Google
 
Web LinuxVirtualServer.org

[PATCH v3 14/14] sysctl: Use ctl_table_size as stopping criteria for lis

To: mcgrof@xxxxxxxxxx
Subject: [PATCH v3 14/14] sysctl: Use ctl_table_size as stopping criteria for list macro
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>, Jani Nikula <jani.nikula@xxxxxxxxxxxxxxx>
From: Joel Granados <joel.granados@xxxxxxxxx>
Date: Wed, 9 Aug 2023 12:50:06 +0200
This is a preparation commit to make it easy to remove the sentinel
elements (empty end markers) from the ctl_table arrays. It both allows
the systematic removal of the sentinels and adds the ctl_table_size
variable to the stopping criteria of the list_for_each_table_entry macro
that traverses all ctl_table arrays. Once all the sentinels are removed
by subsequent commits, ctl_table_size will become the only stopping
criteria in the macro. We don't actually remove any elements in this
commit, but it sets things up to for the removal process to take place.

By adding header->ctl_table_size as an additional stopping criteria for
the list_for_each_table_entry macro, it will execute until it finds an
"empty" ->procname or until the size runs out. Therefore if a ctl_table
array with a sentinel is passed its size will be too big (by one
element) but it will stop on the sentinel. On the other hand, if the
ctl_table array without a sentinel is passed its size will be just write
and there will be no need for a sentinel.

Signed-off-by: Joel Granados <j.granados@xxxxxxxxxxx>
Suggested-by: Jani Nikula <jani.nikula@xxxxxxxxxxxxxxx>
---
 fs/proc/proc_sysctl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 817bc51c58d8..504e847c2a3a 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -19,8 +19,9 @@
 #include <linux/kmemleak.h>
 #include "internal.h"
 
-#define list_for_each_table_entry(entry, header) \
-       for ((entry) = (header->ctl_table); (entry)->procname; (entry)++)
+#define list_for_each_table_entry(entry, header)       \
+       entry = header->ctl_table;                      \
+       for (size_t i = 0 ; i < header->ctl_table_size && entry->procname; ++i, 
entry++)
 
 static const struct dentry_operations proc_sys_dentry_operations;
 static const struct file_operations proc_sys_file_operations;
-- 
2.30.2


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