All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Granados <j.granados@samsung.com>
To: mcgrof@kernel.org, Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>, Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Kees Cook <keescook@chromium.org>,
	Iurii Zaikin <yzaikin@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: willy@infradead.org, josh@joshtriplett.org,
	Joel Granados <j.granados@samsung.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH 06/14] sysctl: Add size to register_sysctl
Date: Wed, 26 Jul 2023 16:06:26 +0200	[thread overview]
Message-ID: <20230726140635.2059334-7-j.granados@samsung.com> (raw)
In-Reply-To: <20230726140635.2059334-1-j.granados@samsung.com>

In order to remove the end element from the ctl_table struct arrays, we
replace the register_syctl function with a macro that will add the
ARRAY_SIZE to the new register_sysctl_sz function. In this way the
callers that are already using an array of ctl_table structs do not have
to change. We *do* change the callers that pass the ctl_table array as a
pointer.

Signed-off-by: Joel Granados <j.granados@samsung.com>
---
 arch/arm64/kernel/armv8_deprecated.c |  2 +-
 arch/s390/appldata/appldata_base.c   |  2 +-
 fs/proc/proc_sysctl.c                | 30 +++++++++++++++-------------
 include/linux/sysctl.h               | 10 ++++++++--
 kernel/ucount.c                      |  2 +-
 net/sysctl_net.c                     |  2 +-
 6 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c
index 1febd412b4d2..e459cfd33711 100644
--- a/arch/arm64/kernel/armv8_deprecated.c
+++ b/arch/arm64/kernel/armv8_deprecated.c
@@ -569,7 +569,7 @@ static void __init register_insn_emulation(struct insn_emulation *insn)
 		sysctl->extra2 = &insn->max;
 		sysctl->proc_handler = emulation_proc_handler;
 
-		register_sysctl("abi", sysctl);
+		register_sysctl_sz("abi", sysctl, 1);
 	}
 }
 
diff --git a/arch/s390/appldata/appldata_base.c b/arch/s390/appldata/appldata_base.c
index bbefe5e86bdf..3b0994625652 100644
--- a/arch/s390/appldata/appldata_base.c
+++ b/arch/s390/appldata/appldata_base.c
@@ -365,7 +365,7 @@ int appldata_register_ops(struct appldata_ops *ops)
 	ops->ctl_table[0].proc_handler = appldata_generic_handler;
 	ops->ctl_table[0].data = ops;
 
-	ops->sysctl_header = register_sysctl(appldata_proc_name, ops->ctl_table);
+	ops->sysctl_header = register_sysctl_sz(appldata_proc_name, ops->ctl_table, 1);
 	if (!ops->sysctl_header)
 		goto out;
 	return 0;
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 8d04f01a89c1..c04293911e7e 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -43,7 +43,7 @@ static struct ctl_table sysctl_mount_point[] = {
  */
 struct ctl_table_header *register_sysctl_mount_point(const char *path)
 {
-	return register_sysctl(path, sysctl_mount_point);
+	return register_sysctl_sz(path, sysctl_mount_point, 0);
 }
 EXPORT_SYMBOL(register_sysctl_mount_point);
 
@@ -1398,7 +1398,7 @@ struct ctl_table_header *__register_sysctl_table(
 }
 
 /**
- * register_sysctl - register a sysctl table
+ * register_sysctl_sz - register a sysctl table
  * @path: The path to the directory the sysctl table is in. If the path
  * 	doesn't exist we will create it for you.
  * @table: the table structure. The calller must ensure the life of the @table
@@ -1408,25 +1408,20 @@ struct ctl_table_header *__register_sysctl_table(
  * 	to call unregister_sysctl_table() and can instead use something like
  * 	register_sysctl_init() which does not care for the result of the syctl
  * 	registration.
+ * @table_size: The number of elements in table.
  *
  * Register a sysctl table. @table should be a filled in ctl_table
  * array. A completely 0 filled entry terminates the table.
  *
  * See __register_sysctl_table for more details.
  */
-struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table)
+struct ctl_table_header *register_sysctl_sz(const char *path, struct ctl_table *table,
+					    size_t table_size)
 {
-	int count = 0;
-	struct ctl_table *entry;
-	struct ctl_table_header t_hdr;
-
-	t_hdr.ctl_table = table;
-	list_for_each_table_entry(entry, (&t_hdr))
-		count++;
 	return __register_sysctl_table(&sysctl_table_root.default_set,
-					path, table, count);
+					path, table, table_size);
 }
-EXPORT_SYMBOL(register_sysctl);
+EXPORT_SYMBOL(register_sysctl_sz);
 
 /**
  * __register_sysctl_init() - register sysctl table to path
@@ -1451,10 +1446,17 @@ EXPORT_SYMBOL(register_sysctl);
 void __init __register_sysctl_init(const char *path, struct ctl_table *table,
 				 const char *table_name)
 {
-	struct ctl_table_header *hdr = register_sysctl(path, table);
+	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);
 
 	if (unlikely(!hdr)) {
-		pr_err("failed when register_sysctl %s to %s\n", table_name, path);
+		pr_err("failed when register_sysctl_sz %s to %s\n", table_name, path);
 		return;
 	}
 	kmemleak_not_leak(hdr);
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 0495c858989f..b1168ae281c9 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -215,6 +215,9 @@ struct ctl_path {
 	const char *procname;
 };
 
+#define register_sysctl(path, table)	\
+	register_sysctl_sz(path, table, ARRAY_SIZE(table))
+
 #ifdef CONFIG_SYSCTL
 
 void proc_sys_poll_notify(struct ctl_table_poll *poll);
@@ -227,7 +230,8 @@ extern void retire_sysctl_set(struct ctl_table_set *set);
 struct ctl_table_header *__register_sysctl_table(
 	struct ctl_table_set *set,
 	const char *path, struct ctl_table *table, size_t table_size);
-struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table);
+struct ctl_table_header *register_sysctl_sz(const char *path, struct ctl_table *table,
+					    size_t table_size);
 void unregister_sysctl_table(struct ctl_table_header * table);
 
 extern int sysctl_init_bases(void);
@@ -262,7 +266,9 @@ static inline struct ctl_table_header *register_sysctl_mount_point(const char *p
 	return NULL;
 }
 
-static inline struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table)
+static inline struct ctl_table_header *register_sysctl_sz(const char *path,
+							  struct ctl_table *table,
+							  size_t table_size)
 {
 	return NULL;
 }
diff --git a/kernel/ucount.c b/kernel/ucount.c
index 2b80264bb79f..4aa6166cb856 100644
--- a/kernel/ucount.c
+++ b/kernel/ucount.c
@@ -365,7 +365,7 @@ static __init int user_namespace_sysctl_init(void)
 	 * default set so that registrations in the child sets work
 	 * properly.
 	 */
-	user_header = register_sysctl("user", empty);
+	user_header = register_sysctl_sz("user", empty, 0);
 	kmemleak_ignore(user_header);
 	BUG_ON(!user_header);
 	BUG_ON(!setup_userns_sysctls(&init_user_ns));
diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index 8ee4b74bc009..d9cbbb51b143 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -101,7 +101,7 @@ __init int net_sysctl_init(void)
 	 * registering "/proc/sys/net" as an empty directory not in a
 	 * network namespace.
 	 */
-	net_header = register_sysctl("net", empty);
+	net_header = register_sysctl_sz("net", empty, 0);
 	if (!net_header)
 		goto out;
 	ret = register_pernet_subsys(&sysctl_pernet_ops);
-- 
2.30.2


  parent reply	other threads:[~2023-07-26 14:08 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20230726140648eucas1p29a92c80fb28550e2087cd0ae190d29bd@eucas1p2.samsung.com>
2023-07-26 14:06 ` [PATCH 00/14] sysctl: Add a size argument to register functions in sysctl Joel Granados
     [not found]   ` <CGME20230726140650eucas1p1f5b2aa9dd8f90989c881f0a2e682b9eb@eucas1p1.samsung.com>
2023-07-26 14:06     ` [PATCH 01/14] sysctl: Prefer ctl_table_header in proc_sysctl Joel Granados
     [not found]   ` <CGME20230726140652eucas1p2a2ac2dd74986bd9ace8380d6f51024ff@eucas1p2.samsung.com>
2023-07-26 14:06     ` [PATCH 02/14] sysctl: Use ctl_table_header in list_for_each_table_entry Joel Granados
     [not found]   ` <CGME20230726140653eucas1p2e234b7cd0af5dc506bd27399b84292a6@eucas1p2.samsung.com>
2023-07-26 14:06     ` [PATCH 03/14] sysctl: Add ctl_table_size to ctl_table_header Joel Granados
2023-07-28 10:48       ` Simon Horman
2023-07-31 12:10         ` Joel Granados
     [not found]   ` <CGME20230726140655eucas1p1c71c8de9edc8441b5262c936731b91a2@eucas1p1.samsung.com>
2023-07-26 14:06     ` [PATCH 04/14] sysctl: Add size argument to init_header Joel Granados
     [not found]   ` <CGME20230726140656eucas1p26cd9da21663d25b51dda75258aaa3b55@eucas1p2.samsung.com>
2023-07-26 14:06     ` [PATCH 05/14] sysctl: Add a size arg to __register_sysctl_table Joel Granados
2023-07-28 10:51       ` Simon Horman
2023-07-28 16:08         ` Joel Granados
     [not found]   ` <CGME20230726140659eucas1p2c3cd9f57dd13c71ddeb78d2480587e72@eucas1p2.samsung.com>
2023-07-26 14:06     ` Joel Granados [this message]
2023-07-26 17:58       ` [PATCH 06/14] sysctl: Add size to register_sysctl Luis Chamberlain
2023-07-27 12:22         ` Joel Granados
2023-07-27 12:22           ` Joel Granados
2023-07-27 15:42           ` Luis Chamberlain
2023-07-27 15:42             ` Luis Chamberlain
2023-07-28  7:41             ` Joel Granados
2023-07-28  7:41               ` Joel Granados
     [not found]   ` <CGME20230726140700eucas1p1e6b16e884362ebec50f6712b3f11a533@eucas1p1.samsung.com>
2023-07-26 14:06     ` [PATCH 07/14] sysctl: Add size arg to __register_sysctl_init Joel Granados
2023-07-28 10:56       ` Simon Horman
2023-07-28 16:11         ` Joel Granados
     [not found]   ` <CGME20230726140702eucas1p20c75fc21d675ea267dd2ad4ebd6e60b4@eucas1p2.samsung.com>
2023-07-26 14:06     ` [PATCH 08/14] sysctl: Add size to register_net_sysctl function Joel Granados
     [not found]   ` <CGME20230726140703eucas1p2786577bcc67d5ae434671dac11870c60@eucas1p2.samsung.com>
2023-07-26 14:06     ` [PATCH 09/14] ax.25: Update to register_net_sysctl_sz Joel Granados
2023-07-26 18:00       ` Luis Chamberlain
2023-07-27 12:31         ` Joel Granados
2023-07-27 12:31           ` Joel Granados
2023-07-27 15:44           ` Luis Chamberlain
2023-07-28  7:35             ` Joel Granados
2023-07-28  7:35               ` Joel Granados
2023-07-28 18:16               ` Luis Chamberlain
2023-07-31  7:09                 ` Joel Granados
2023-07-31  7:09                   ` Joel Granados
2023-07-27 15:38         ` Joel Granados
2023-07-27 15:38           ` Joel Granados
2023-07-27 15:50           ` Luis Chamberlain
     [not found]   ` <CGME20230726140706eucas1p1b11e5f0bd17f0de19af9608cbd8d17f3@eucas1p1.samsung.com>
2023-07-26 14:06     ` [PATCH 10/14] netfilter: " Joel Granados
2023-07-26 14:06       ` [Bridge] " Joel Granados
2023-07-26 18:01       ` Luis Chamberlain
2023-07-26 18:01         ` [Bridge] " Luis Chamberlain
     [not found]   ` <CGME20230726140709eucas1p2033d64aec69a1962fd7e64c57ad60adc@eucas1p2.samsung.com>
2023-07-26 14:06     ` [PATCH 11/14] networking: " Joel Granados
2023-07-26 18:05       ` Luis Chamberlain
2023-07-27  0:33         ` David Ahern
2023-07-27 12:33         ` Joel Granados
2023-07-28  7:08         ` Joel Granados
     [not found]   ` <CGME20230726140711eucas1p25a947afeef5593e21578f778355db192@eucas1p2.samsung.com>
2023-07-26 14:06     ` [PATCH 12/14] vrf: " Joel Granados
     [not found]   ` <CGME20230726140712eucas1p1bc7b2d150482936d974ceba9c51d7bc4@eucas1p1.samsung.com>
2023-07-26 14:06     ` [PATCH 13/14] sysctl: SIZE_MAX->ARRAY_SIZE in register_net_sysctl Joel Granados
     [not found]   ` <CGME20230726140714eucas1p186bad44daf14c4c8c93f9aaf52deade5@eucas1p1.samsung.com>
2023-07-26 14:06     ` [PATCH 14/14] sysctl: Use size as stopping criteria for list macro Joel Granados
2023-07-26 18:15   ` [PATCH 00/14] sysctl: Add a size argument to register functions in sysctl Luis Chamberlain
2023-07-27 11:43     ` Joel Granados
2023-07-27 15:39       ` Luis Chamberlain
2023-07-28  7:04         ` Joel Granados

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=20230726140635.2059334-7-j.granados@samsung.com \
    --to=j.granados@samsung.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=catalin.marinas@arm.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=josh@joshtriplett.org \
    --cc=keescook@chromium.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=svens@linux.ibm.com \
    --cc=will@kernel.org \
    --cc=willy@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.