Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit d7a76ec

Browse files
committed
sysctl: Remove check for sentinel element in ctl_table arrays
Use ARRAY_SIZE exclusively by removing the check to ->procname in the stopping criteria of the loops traversing ctl_table arrays. This commit finalizes the removal of the sentinel elements at the end of ctl_table arrays which reduces the build time size and run time memory bloat by ~64 bytes per sentinel (further information Link : https://lore.kernel.org/all/ZO5Yx5JFogGi%2FcBo@bombadil.infradead.org/) Remove the entry->procname evaluation from the for loop stopping criteria in sysctl and sysctl_net. Signed-off-by: Joel Granados <j.granados@samsung.com>
1 parent e2a6c47 commit d7a76ec

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

fs/proc/proc_sysctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#define list_for_each_table_entry(entry, header) \
2323
entry = header->ctl_table; \
24-
for (size_t i = 0 ; i < header->ctl_table_size && entry->procname; ++i, entry++)
24+
for (size_t i = 0 ; i < header->ctl_table_size; ++i, entry++)
2525

2626
static const struct dentry_operations proc_sys_dentry_operations;
2727
static const struct file_operations proc_sys_file_operations;

net/sysctl_net.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static void ensure_safe_net_sysctl(struct net *net, const char *path,
127127

128128
pr_debug("Registering net sysctl (net %p): %s\n", net, path);
129129
ent = table;
130-
for (size_t i = 0; i < table_size && ent->procname; ent++, i++) {
130+
for (size_t i = 0; i < table_size; ent++, i++) {
131131
unsigned long addr;
132132
const char *where;
133133

@@ -165,17 +165,10 @@ struct ctl_table_header *register_net_sysctl_sz(struct net *net,
165165
struct ctl_table *table,
166166
size_t table_size)
167167
{
168-
int count;
169-
struct ctl_table *entry;
170-
171168
if (!net_eq(net, &init_net))
172169
ensure_safe_net_sysctl(net, path, table, table_size);
173170

174-
entry = table;
175-
for (count = 0 ; count < table_size && entry->procname; entry++, count++)
176-
;
177-
178-
return __register_sysctl_table(&net->sysctls, path, table, count);
171+
return __register_sysctl_table(&net->sysctls, path, table, table_size);
179172
}
180173
EXPORT_SYMBOL_GPL(register_net_sysctl_sz);
181174

0 commit comments

Comments
 (0)