]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sysctl: Remove check for sentinel element in ctl_table arrays
authorJoel Granados <j.granados@samsung.com>
Tue, 4 Jun 2024 06:29:21 +0000 (08:29 +0200)
committerJoel Granados <j.granados@samsung.com>
Thu, 13 Jun 2024 08:50:52 +0000 (10:50 +0200)
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>
fs/proc/proc_sysctl.c
net/sysctl_net.c

index c467e36741d03bb02d97e66f00ceefc57cf03c7b..832de1c64b5aa0e157b10c4fe8354e682065478b 100644 (file)
@@ -21,7 +21,7 @@
 
 #define list_for_each_table_entry(entry, header)       \
        entry = header->ctl_table;                      \
-       for (size_t i = 0 ; i < header->ctl_table_size && entry->procname; ++i, entry++)
+       for (size_t i = 0 ; i < header->ctl_table_size; ++i, entry++)
 
 static const struct dentry_operations proc_sys_dentry_operations;
 static const struct file_operations proc_sys_file_operations;
index f5017012a049312a826b3e382ff9381bc4a25410..19e8048241bacb18de853d3b904d0f97fd2fe78a 100644 (file)
@@ -127,7 +127,7 @@ static void ensure_safe_net_sysctl(struct net *net, const char *path,
 
        pr_debug("Registering net sysctl (net %p): %s\n", net, path);
        ent = table;
-       for (size_t i = 0; i < table_size && ent->procname; ent++, i++) {
+       for (size_t i = 0; i < table_size; ent++, i++) {
                unsigned long addr;
                const char *where;
 
@@ -165,17 +165,10 @@ struct ctl_table_header *register_net_sysctl_sz(struct net *net,
                                                struct ctl_table *table,
                                                size_t table_size)
 {
-       int count;
-       struct ctl_table *entry;
-
        if (!net_eq(net, &init_net))
                ensure_safe_net_sysctl(net, path, table, table_size);
 
-       entry = table;
-       for (count = 0 ; count < table_size && entry->procname; entry++, count++)
-               ;
-
-       return __register_sysctl_table(&net->sysctls, path, table, count);
+       return __register_sysctl_table(&net->sysctls, path, table, table_size);
 }
 EXPORT_SYMBOL_GPL(register_net_sysctl_sz);