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

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>

+3 -10
+1 -1
fs/proc/proc_sysctl.c
··· 21 21 22 22 #define list_for_each_table_entry(entry, header) \ 23 23 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++) 25 25 26 26 static const struct dentry_operations proc_sys_dentry_operations; 27 27 static const struct file_operations proc_sys_file_operations;
+2 -9
net/sysctl_net.c
··· 127 127 128 128 pr_debug("Registering net sysctl (net %p): %s\n", net, path); 129 129 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++) { 131 131 unsigned long addr; 132 132 const char *where; 133 133 ··· 165 165 struct ctl_table *table, 166 166 size_t table_size) 167 167 { 168 - int count; 169 - struct ctl_table *entry; 170 - 171 168 if (!net_eq(net, &init_net)) 172 169 ensure_safe_net_sysctl(net, path, table, table_size); 173 170 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); 179 172 } 180 173 EXPORT_SYMBOL_GPL(register_net_sysctl_sz); 181 174