Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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@samsung.com>
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>

authored by

Joel Granados and committed by
Luis Chamberlain
3bc269cf 9edbfe92

+6 -11
+3 -9
fs/proc/proc_sysctl.c
··· 1433 1433 * lifetime use of the sysctl. 1434 1434 * @table_name: The name of sysctl table, only used for log printing when 1435 1435 * registration fails 1436 + * @table_size: The number of elements in table 1436 1437 * 1437 1438 * The sysctl interface is used by userspace to query or modify at runtime 1438 1439 * a predefined value set on a variable. These variables however have default ··· 1446 1445 * Context: if your base directory does not exist it will be created for you. 1447 1446 */ 1448 1447 void __init __register_sysctl_init(const char *path, struct ctl_table *table, 1449 - const char *table_name) 1448 + const char *table_name, size_t table_size) 1450 1449 { 1451 - int count = 0; 1452 - struct ctl_table *entry; 1453 - struct ctl_table_header t_hdr, *hdr; 1454 - 1455 - t_hdr.ctl_table = table; 1456 - list_for_each_table_entry(entry, (&t_hdr)) 1457 - count++; 1458 - hdr = register_sysctl_sz(path, table, count); 1450 + struct ctl_table_header *hdr = register_sysctl_sz(path, table, table_size); 1459 1451 1460 1452 if (unlikely(!hdr)) { 1461 1453 pr_err("failed when register_sysctl_sz %s to %s\n", table_name, path);
+3 -2
include/linux/sysctl.h
··· 236 236 237 237 extern int sysctl_init_bases(void); 238 238 extern void __register_sysctl_init(const char *path, struct ctl_table *table, 239 - const char *table_name); 240 - #define register_sysctl_init(path, table) __register_sysctl_init(path, table, #table) 239 + const char *table_name, size_t table_size); 240 + #define register_sysctl_init(path, table) \ 241 + __register_sysctl_init(path, table, #table, ARRAY_SIZE(table)) 241 242 extern struct ctl_table_header *register_sysctl_mount_point(const char *path); 242 243 243 244 void do_sysctl_args(void);