Skip to content

Commit 3bc269c

Browse files
Joelgranadosmcgrof
authored andcommitted
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 <[email protected]> Suggested-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 9edbfe9 commit 3bc269c

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

fs/proc/proc_sysctl.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,7 @@ EXPORT_SYMBOL(register_sysctl_sz);
14331433
* lifetime use of the sysctl.
14341434
* @table_name: The name of sysctl table, only used for log printing when
14351435
* registration fails
1436+
* @table_size: The number of elements in table
14361437
*
14371438
* The sysctl interface is used by userspace to query or modify at runtime
14381439
* a predefined value set on a variable. These variables however have default
@@ -1445,16 +1446,9 @@ EXPORT_SYMBOL(register_sysctl_sz);
14451446
* Context: if your base directory does not exist it will be created for you.
14461447
*/
14471448
void __init __register_sysctl_init(const char *path, struct ctl_table *table,
1448-
const char *table_name)
1449+
const char *table_name, size_t table_size)
14491450
{
1450-
int count = 0;
1451-
struct ctl_table *entry;
1452-
struct ctl_table_header t_hdr, *hdr;
1453-
1454-
t_hdr.ctl_table = table;
1455-
list_for_each_table_entry(entry, (&t_hdr))
1456-
count++;
1457-
hdr = register_sysctl_sz(path, table, count);
1451+
struct ctl_table_header *hdr = register_sysctl_sz(path, table, table_size);
14581452

14591453
if (unlikely(!hdr)) {
14601454
pr_err("failed when register_sysctl_sz %s to %s\n", table_name, path);

include/linux/sysctl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ void unregister_sysctl_table(struct ctl_table_header * table);
236236

237237
extern int sysctl_init_bases(void);
238238
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))
241242
extern struct ctl_table_header *register_sysctl_mount_point(const char *path);
242243

243244
void do_sysctl_args(void);

0 commit comments

Comments
 (0)