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

net: ipv{6,4}: Remove the now superfluous sentinel elements from ctl_table array

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/ZO5Yx5JFogGi%2FcBo@bombadil.infradead.org/)

* Remove sentinel element from ctl_table structs.
* Remove the zeroing out of an array element (to make it look like a
sentinel) in sysctl_route_net_init And ipv6_route_sysctl_init.
This is not longer needed and is safe after commit c899710fe7f9
("networking: Update to register_net_sysctl_sz") added the array size
to the ctl_table registration.
* Remove extra sentinel element in the declaration of devinet_vars.
* Removed the "-1" in __devinet_sysctl_register, sysctl_route_net_init,
ipv6_sysctl_net_init and ipv4_sysctl_init_net that adjusted for having
an extra empty element when looping over ctl_table arrays
* Replace the for loop stop condition in __addrconf_sysctl_register that
tests for procname == NULL with one that depends on array size
* Removing the unprivileged user check in ipv6_route_sysctl_init is
safe as it is replaced by calling ipv6_route_sysctl_table_size;
introduced in commit c899710fe7f9 ("networking: Update to
register_net_sysctl_sz")
* Use a table_size variable to keep the value of ARRAY_SIZE

Signed-off-by: Joel Granados <j.granados@samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Joel Granados and committed by
David S. Miller
1c106eb0 ce218712

+13 -35
+2 -3
net/ipv4/devinet.c
··· 2520 2520 2521 2521 static struct devinet_sysctl_table { 2522 2522 struct ctl_table_header *sysctl_header; 2523 - struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX]; 2523 + struct ctl_table devinet_vars[IPV4_DEVCONF_MAX]; 2524 2524 } devinet_sysctl = { 2525 2525 .devinet_vars = { 2526 2526 DEVINET_SYSCTL_COMPLEX_ENTRY(FORWARDING, "forwarding", ··· 2583 2583 if (!t) 2584 2584 goto out; 2585 2585 2586 - for (i = 0; i < ARRAY_SIZE(t->devinet_vars) - 1; i++) { 2586 + for (i = 0; i < ARRAY_SIZE(t->devinet_vars); i++) { 2587 2587 t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf; 2588 2588 t->devinet_vars[i].extra1 = p; 2589 2589 t->devinet_vars[i].extra2 = net; ··· 2657 2657 .extra1 = &ipv4_devconf, 2658 2658 .extra2 = &init_net, 2659 2659 }, 2660 - { }, 2661 2660 }; 2662 2661 #endif 2663 2662
-2
net/ipv4/ip_fragment.c
··· 580 580 .proc_handler = proc_dointvec_minmax, 581 581 .extra1 = &dist_min, 582 582 }, 583 - { } 584 583 }; 585 584 586 585 /* secret interval has been deprecated */ ··· 592 593 .mode = 0644, 593 594 .proc_handler = proc_dointvec_jiffies, 594 595 }, 595 - { } 596 596 }; 597 597 598 598 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
+2 -6
net/ipv4/route.c
··· 3496 3496 .mode = 0644, 3497 3497 .proc_handler = proc_dointvec, 3498 3498 }, 3499 - { } 3500 3499 }; 3501 3500 3502 3501 static const char ipv4_route_flush_procname[] = "flush"; ··· 3529 3530 .mode = 0644, 3530 3531 .proc_handler = proc_dointvec, 3531 3532 }, 3532 - { }, 3533 3533 }; 3534 3534 3535 3535 static __net_init int sysctl_route_net_init(struct net *net) ··· 3546 3548 3547 3549 /* Don't export non-whitelisted sysctls to unprivileged users */ 3548 3550 if (net->user_ns != &init_user_ns) { 3549 - if (tbl[0].procname != ipv4_route_flush_procname) { 3550 - tbl[0].procname = NULL; 3551 + if (tbl[0].procname != ipv4_route_flush_procname) 3551 3552 table_size = 0; 3552 - } 3553 3553 } 3554 3554 3555 3555 /* Update the variables to point into the current struct net 3556 3556 * except for the first element flush 3557 3557 */ 3558 - for (i = 1; i < ARRAY_SIZE(ipv4_route_netns_table) - 1; i++) 3558 + for (i = 1; i < table_size; i++) 3559 3559 tbl[i].data += (void *)net - (void *)&init_net; 3560 3560 } 3561 3561 tbl[0].extra1 = net;
+3 -4
net/ipv4/sysctl_net_ipv4.c
··· 575 575 .extra1 = &sysctl_fib_sync_mem_min, 576 576 .extra2 = &sysctl_fib_sync_mem_max, 577 577 }, 578 - { } 579 578 }; 580 579 581 580 static struct ctl_table ipv4_net_table[] = { ··· 1501 1502 .proc_handler = proc_dou8vec_minmax, 1502 1503 .extra1 = SYSCTL_ONE, 1503 1504 }, 1504 - { } 1505 1505 }; 1506 1506 1507 1507 static __net_init int ipv4_sysctl_init_net(struct net *net) 1508 1508 { 1509 + size_t table_size = ARRAY_SIZE(ipv4_net_table); 1509 1510 struct ctl_table *table; 1510 1511 1511 1512 table = ipv4_net_table; ··· 1516 1517 if (!table) 1517 1518 goto err_alloc; 1518 1519 1519 - for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) { 1520 + for (i = 0; i < table_size; i++) { 1520 1521 if (table[i].data) { 1521 1522 /* Update the variables to point into 1522 1523 * the current struct net ··· 1532 1533 } 1533 1534 1534 1535 net->ipv4.ipv4_hdr = register_net_sysctl_sz(net, "net/ipv4", table, 1535 - ARRAY_SIZE(ipv4_net_table)); 1536 + table_size); 1536 1537 if (!net->ipv4.ipv4_hdr) 1537 1538 goto err_reg; 1538 1539
-1
net/ipv4/xfrm4_policy.c
··· 152 152 .mode = 0644, 153 153 .proc_handler = proc_dointvec, 154 154 }, 155 - { } 156 155 }; 157 156 158 157 static __net_init int xfrm4_net_sysctl_init(struct net *net)
+3 -5
net/ipv6/addrconf.c
··· 7184 7184 .extra1 = SYSCTL_ZERO, 7185 7185 .extra2 = SYSCTL_TWO, 7186 7186 }, 7187 - { 7188 - /* sentinel */ 7189 - } 7190 7187 }; 7191 7188 7192 7189 static int __addrconf_sysctl_register(struct net *net, char *dev_name, 7193 7190 struct inet6_dev *idev, struct ipv6_devconf *p) 7194 7191 { 7192 + size_t table_size = ARRAY_SIZE(addrconf_sysctl); 7195 7193 int i, ifindex; 7196 7194 struct ctl_table *table; 7197 7195 char path[sizeof("net/ipv6/conf/") + IFNAMSIZ]; ··· 7198 7200 if (!table) 7199 7201 goto out; 7200 7202 7201 - for (i = 0; table[i].data; i++) { 7203 + for (i = 0; i < table_size; i++) { 7202 7204 table[i].data += (char *)p - (char *)&ipv6_devconf; 7203 7205 /* If one of these is already set, then it is not safe to 7204 7206 * overwrite either of them: this makes proc_dointvec_minmax ··· 7213 7215 snprintf(path, sizeof(path), "net/ipv6/conf/%s", dev_name); 7214 7216 7215 7217 p->sysctl_header = register_net_sysctl_sz(net, path, table, 7216 - ARRAY_SIZE(addrconf_sysctl)); 7218 + table_size); 7217 7219 if (!p->sysctl_header) 7218 7220 goto free; 7219 7221
-1
net/ipv6/icmp.c
··· 1206 1206 .extra1 = SYSCTL_ZERO, 1207 1207 .extra2 = SYSCTL_ONE, 1208 1208 }, 1209 - { }, 1210 1209 }; 1211 1210 1212 1211 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
-2
net/ipv6/reassembly.c
··· 436 436 .mode = 0644, 437 437 .proc_handler = proc_dointvec_jiffies, 438 438 }, 439 - { } 440 439 }; 441 440 442 441 /* secret interval has been deprecated */ ··· 448 449 .mode = 0644, 449 450 .proc_handler = proc_dointvec_jiffies, 450 451 }, 451 - { } 452 452 }; 453 453 454 454 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
-5
net/ipv6/route.c
··· 6428 6428 .extra1 = SYSCTL_ZERO, 6429 6429 .extra2 = SYSCTL_ONE, 6430 6430 }, 6431 - { } 6432 6431 }; 6433 6432 6434 6433 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net) ··· 6451 6452 table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss; 6452 6453 table[9].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval; 6453 6454 table[10].data = &net->ipv6.sysctl.skip_notify_on_dev_down; 6454 - 6455 - /* Don't export sysctls to unprivileged users */ 6456 - if (net->user_ns != &init_user_ns) 6457 - table[1].procname = NULL; 6458 6455 } 6459 6456 6460 6457 return table;
+3 -5
net/ipv6/sysctl_net_ipv6.c
··· 213 213 .proc_handler = proc_doulongvec_minmax, 214 214 .extra2 = &ioam6_id_wide_max, 215 215 }, 216 - { } 217 216 }; 218 217 219 218 static struct ctl_table ipv6_rotable[] = { ··· 247 248 .proc_handler = proc_dointvec, 248 249 }, 249 250 #endif /* CONFIG_NETLABEL */ 250 - { } 251 251 }; 252 252 253 253 static int __net_init ipv6_sysctl_net_init(struct net *net) 254 254 { 255 + size_t table_size = ARRAY_SIZE(ipv6_table_template); 255 256 struct ctl_table *ipv6_table; 256 257 struct ctl_table *ipv6_route_table; 257 258 struct ctl_table *ipv6_icmp_table; ··· 263 264 if (!ipv6_table) 264 265 goto out; 265 266 /* Update the variables to point into the current struct net */ 266 - for (i = 0; i < ARRAY_SIZE(ipv6_table_template) - 1; i++) 267 + for (i = 0; i < table_size; i++) 267 268 ipv6_table[i].data += (void *)net - (void *)&init_net; 268 269 269 270 ipv6_route_table = ipv6_route_sysctl_init(net); ··· 275 276 goto out_ipv6_route_table; 276 277 277 278 net->ipv6.sysctl.hdr = register_net_sysctl_sz(net, "net/ipv6", 278 - ipv6_table, 279 - ARRAY_SIZE(ipv6_table_template)); 279 + ipv6_table, table_size); 280 280 if (!net->ipv6.sysctl.hdr) 281 281 goto out_ipv6_icmp_table; 282 282
-1
net/ipv6/xfrm6_policy.c
··· 184 184 .mode = 0644, 185 185 .proc_handler = proc_dointvec, 186 186 }, 187 - { } 188 187 }; 189 188 190 189 static int __net_init xfrm6_net_sysctl_init(struct net *net)