Skip to content

Commit 9edbfe9

Browse files
Joelgranadosmcgrof
authored andcommitted
sysctl: Add size to register_sysctl
This commit adds table_size to register_sysctl 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 either passing the table_size explicitly or using ARRAY_SIZE on the ctl_table 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 change. For the callers that pass a ctl_table array pointer, we pass the table_size to register_sysctl_sz instead of the macro. Signed-off-by: Joel Granados <[email protected]> Suggested-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent bff97cf commit 9edbfe9

File tree

6 files changed

+28
-20
lines changed

6 files changed

+28
-20
lines changed

arch/arm64/kernel/armv8_deprecated.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ static void __init register_insn_emulation(struct insn_emulation *insn)
569569
sysctl->extra2 = &insn->max;
570570
sysctl->proc_handler = emulation_proc_handler;
571571

572-
register_sysctl("abi", sysctl);
572+
register_sysctl_sz("abi", sysctl, 1);
573573
}
574574
}
575575

arch/s390/appldata/appldata_base.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ int appldata_register_ops(struct appldata_ops *ops)
365365
ops->ctl_table[0].proc_handler = appldata_generic_handler;
366366
ops->ctl_table[0].data = ops;
367367

368-
ops->sysctl_header = register_sysctl(appldata_proc_name, ops->ctl_table);
368+
ops->sysctl_header = register_sysctl_sz(appldata_proc_name, ops->ctl_table, 1);
369369
if (!ops->sysctl_header)
370370
goto out;
371371
return 0;

fs/proc/proc_sysctl.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static struct ctl_table sysctl_mount_point[] = {
4343
*/
4444
struct ctl_table_header *register_sysctl_mount_point(const char *path)
4545
{
46-
return register_sysctl(path, sysctl_mount_point);
46+
return register_sysctl_sz(path, sysctl_mount_point, 0);
4747
}
4848
EXPORT_SYMBOL(register_sysctl_mount_point);
4949

@@ -1399,7 +1399,7 @@ struct ctl_table_header *__register_sysctl_table(
13991399
}
14001400

14011401
/**
1402-
* register_sysctl - register a sysctl table
1402+
* register_sysctl_sz - register a sysctl table
14031403
* @path: The path to the directory the sysctl table is in. If the path
14041404
* doesn't exist we will create it for you.
14051405
* @table: the table structure. The calller must ensure the life of the @table
@@ -1409,25 +1409,20 @@ struct ctl_table_header *__register_sysctl_table(
14091409
* to call unregister_sysctl_table() and can instead use something like
14101410
* register_sysctl_init() which does not care for the result of the syctl
14111411
* registration.
1412+
* @table_size: The number of elements in table.
14121413
*
14131414
* Register a sysctl table. @table should be a filled in ctl_table
14141415
* array. A completely 0 filled entry terminates the table.
14151416
*
14161417
* See __register_sysctl_table for more details.
14171418
*/
1418-
struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table)
1419+
struct ctl_table_header *register_sysctl_sz(const char *path, struct ctl_table *table,
1420+
size_t table_size)
14191421
{
1420-
int count = 0;
1421-
struct ctl_table *entry;
1422-
struct ctl_table_header t_hdr;
1423-
1424-
t_hdr.ctl_table = table;
1425-
list_for_each_table_entry(entry, (&t_hdr))
1426-
count++;
14271422
return __register_sysctl_table(&sysctl_table_root.default_set,
1428-
path, table, count);
1423+
path, table, table_size);
14291424
}
1430-
EXPORT_SYMBOL(register_sysctl);
1425+
EXPORT_SYMBOL(register_sysctl_sz);
14311426

14321427
/**
14331428
* __register_sysctl_init() - register sysctl table to path
@@ -1452,10 +1447,17 @@ EXPORT_SYMBOL(register_sysctl);
14521447
void __init __register_sysctl_init(const char *path, struct ctl_table *table,
14531448
const char *table_name)
14541449
{
1455-
struct ctl_table_header *hdr = register_sysctl(path, table);
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);
14561458

14571459
if (unlikely(!hdr)) {
1458-
pr_err("failed when register_sysctl %s to %s\n", table_name, path);
1460+
pr_err("failed when register_sysctl_sz %s to %s\n", table_name, path);
14591461
return;
14601462
}
14611463
kmemleak_not_leak(hdr);

include/linux/sysctl.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ struct ctl_path {
215215
const char *procname;
216216
};
217217

218+
#define register_sysctl(path, table) \
219+
register_sysctl_sz(path, table, ARRAY_SIZE(table))
220+
218221
#ifdef CONFIG_SYSCTL
219222

220223
void proc_sys_poll_notify(struct ctl_table_poll *poll);
@@ -227,7 +230,8 @@ extern void retire_sysctl_set(struct ctl_table_set *set);
227230
struct ctl_table_header *__register_sysctl_table(
228231
struct ctl_table_set *set,
229232
const char *path, struct ctl_table *table, size_t table_size);
230-
struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table);
233+
struct ctl_table_header *register_sysctl_sz(const char *path, struct ctl_table *table,
234+
size_t table_size);
231235
void unregister_sysctl_table(struct ctl_table_header * table);
232236

233237
extern int sysctl_init_bases(void);
@@ -262,7 +266,9 @@ static inline struct ctl_table_header *register_sysctl_mount_point(const char *p
262266
return NULL;
263267
}
264268

265-
static inline struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table)
269+
static inline struct ctl_table_header *register_sysctl_sz(const char *path,
270+
struct ctl_table *table,
271+
size_t table_size)
266272
{
267273
return NULL;
268274
}

kernel/ucount.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static __init int user_namespace_sysctl_init(void)
365365
* default set so that registrations in the child sets work
366366
* properly.
367367
*/
368-
user_header = register_sysctl("user", empty);
368+
user_header = register_sysctl_sz("user", empty, 0);
369369
kmemleak_ignore(user_header);
370370
BUG_ON(!user_header);
371371
BUG_ON(!setup_userns_sysctls(&init_user_ns));

net/sysctl_net.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ __init int net_sysctl_init(void)
101101
* registering "/proc/sys/net" as an empty directory not in a
102102
* network namespace.
103103
*/
104-
net_header = register_sysctl("net", empty);
104+
net_header = register_sysctl_sz("net", empty, 0);
105105
if (!net_header)
106106
goto out;
107107
ret = register_pernet_subsys(&sysctl_pernet_ops);

0 commit comments

Comments
 (0)