[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230809105006.1198165-8-j.granados@samsung.com>
Date: Wed, 9 Aug 2023 12:49:59 +0200
From: Joel Granados <joel.granados@...il.com>
To: mcgrof@...nel.org
Cc: rds-devel@....oracle.com, "David S. Miller" <davem@...emloft.net>,
Florian Westphal <fw@...len.de>, willy@...radead.org,
Jan Karcher <jaka@...ux.ibm.com>,
Wen Gu <guwen@...ux.alibaba.com>,
Simon Horman <horms@...ge.net.au>,
Tony Lu <tonylu@...ux.alibaba.com>, linux-wpan@...r.kernel.org,
Matthieu Baerts <matthieu.baerts@...sares.net>,
Christian Borntraeger <borntraeger@...ux.ibm.com>,
mptcp@...ts.linux.dev, Heiko Carstens <hca@...ux.ibm.com>,
Stefan Schmidt <stefan@...enfreihafen.org>,
Will Deacon <will@...nel.org>, Julian Anastasov <ja@....bg>,
netfilter-devel@...r.kernel.org, Joerg Reuter <jreuter@...na.de>,
linux-kernel@...r.kernel.org,
Alexander Gordeev <agordeev@...ux.ibm.com>,
linux-sctp@...r.kernel.org, Xin Long <lucien.xin@...il.com>,
Herbert Xu <herbert@...dor.apana.org.au>,
linux-hams@...r.kernel.org, Vasily Gorbik <gor@...ux.ibm.com>,
coreteam@...filter.org, Ralf Baechle <ralf@...ux-mips.org>,
Steffen Klassert <steffen.klassert@...unet.com>,
Pablo Neira Ayuso <pablo@...filter.org>,
keescook@...omium.org, Roopa Prabhu <roopa@...dia.com>,
David Ahern <dsahern@...nel.org>,
linux-arm-kernel@...ts.infradead.org,
Catalin Marinas <catalin.marinas@....com>,
Jozsef Kadlecsik <kadlec@...filter.org>,
Wenjia Zhang <wenjia@...ux.ibm.com>, josh@...htriplett.org,
linux-fsdevel@...r.kernel.org,
Alexander Aring <alex.aring@...il.com>,
Nikolay Aleksandrov <razor@...ckwall.org>,
netdev@...r.kernel.org,
Santosh Shilimkar <santosh.shilimkar@...cle.com>,
linux-s390@...r.kernel.org, Sven Schnelle <svens@...ux.ibm.com>,
"D. Wythe" <alibuda@...ux.alibaba.com>,
Eric Dumazet <edumazet@...gle.com>, lvs-devel@...r.kernel.org,
linux-rdma@...r.kernel.org, Paolo Abeni <pabeni@...hat.com>,
Iurii Zaikin <yzaikin@...gle.com>,
Marcelo Ricardo Leitner <marcelo.leitner@...il.com>,
bridge@...ts.linux-foundation.org,
Karsten Graul <kgraul@...ux.ibm.com>,
Mat Martineau <martineau@...nel.org>,
Miquel Raynal <miquel.raynal@...tlin.com>,
Jakub Kicinski <kuba@...nel.org>,
Joel Granados <j.granados@...sung.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: [PATCH v3 07/14] sysctl: Add size arg to __register_sysctl_init
This commit adds table_size to __register_sysctl_init in preparation for
the removal of the sentinel elements in the ctl_table arrays (last empty
markers). And though we do *not* remove any sentinels in this commit, we
set things up by calculating the ctl_table array size with ARRAY_SIZE.
We add a table_size argument to __register_sysctl_init and modify the
register_sysctl_init macro to calculate the array size with ARRAY_SIZE.
The original callers do not need to be updated as they will go through
the new macro.
Signed-off-by: Joel Granados <j.granados@...sung.com>
Suggested-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
---
fs/proc/proc_sysctl.c | 12 +++---------
include/linux/sysctl.h | 5 +++--
2 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 80d3e2f61947..817bc51c58d8 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -1433,6 +1433,7 @@ EXPORT_SYMBOL(register_sysctl_sz);
* lifetime use of the sysctl.
* @table_name: The name of sysctl table, only used for log printing when
* registration fails
+ * @table_size: The number of elements in table
*
* The sysctl interface is used by userspace to query or modify at runtime
* a predefined value set on a variable. These variables however have default
@@ -1445,16 +1446,9 @@ EXPORT_SYMBOL(register_sysctl_sz);
* Context: if your base directory does not exist it will be created for you.
*/
void __init __register_sysctl_init(const char *path, struct ctl_table *table,
- const char *table_name)
+ const char *table_name, size_t table_size)
{
- int count = 0;
- struct ctl_table *entry;
- struct ctl_table_header t_hdr, *hdr;
-
- t_hdr.ctl_table = table;
- list_for_each_table_entry(entry, (&t_hdr))
- count++;
- hdr = register_sysctl_sz(path, table, count);
+ struct ctl_table_header *hdr = register_sysctl_sz(path, table, table_size);
if (unlikely(!hdr)) {
pr_err("failed when register_sysctl_sz %s to %s\n", table_name, path);
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index b1168ae281c9..09d7429d67c0 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -236,8 +236,9 @@ void unregister_sysctl_table(struct ctl_table_header * table);
extern int sysctl_init_bases(void);
extern void __register_sysctl_init(const char *path, struct ctl_table *table,
- const char *table_name);
-#define register_sysctl_init(path, table) __register_sysctl_init(path, table, #table)
+ const char *table_name, size_t table_size);
+#define register_sysctl_init(path, table) \
+ __register_sysctl_init(path, table, #table, ARRAY_SIZE(table))
extern struct ctl_table_header *register_sysctl_mount_point(const char *path);
void do_sysctl_args(void);
--
2.30.2
Powered by blists - more mailing lists