sysctl: Add size arg to __register_sysctl_init
authorJoel Granados <joel.granados@gmail.com>
Wed, 9 Aug 2023 10:49:59 +0000 (12:49 +0200)
committerLuis Chamberlain <mcgrof@kernel.org>
Tue, 15 Aug 2023 22:26:17 +0000 (15:26 -0700)
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@samsung.com>
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
fs/proc/proc_sysctl.c
include/linux/sysctl.h

index 80d3e2f619474da967afc7955556c0f200d611a6..817bc51c58d809f968a045813094beeb9852a05c 100644 (file)
@@ -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);
index b1168ae281c91f475ab41ee8a8a7b7bfe86d8e17..09d7429d67c0ee1d0ea14622c48bee0583225ac8 100644 (file)
@@ -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);