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

net: 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 neigh_sysctl_register and lowpan_frags_ns_sysctl_register
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.
* Replace the for loop stop condition in sysctl_core_net_init that tests
for procname == NULL with one that depends on array size
* Removed the "-1" in mpls_net_init that adjusted for having an extra
empty element when looping over ctl_table arrays
* 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
ce218712 a17ef9e6

+14 -26
+1 -4
net/core/neighbour.c
··· 3733 3733 3734 3734 static struct neigh_sysctl_table { 3735 3735 struct ctl_table_header *sysctl_header; 3736 - struct ctl_table neigh_vars[NEIGH_VAR_MAX + 1]; 3736 + struct ctl_table neigh_vars[NEIGH_VAR_MAX]; 3737 3737 } neigh_sysctl_template __read_mostly = { 3738 3738 .neigh_vars = { 3739 3739 NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(MCAST_PROBES, "mcast_solicit"), ··· 3784 3784 .extra2 = SYSCTL_INT_MAX, 3785 3785 .proc_handler = proc_dointvec_minmax, 3786 3786 }, 3787 - {}, 3788 3787 }, 3789 3788 }; 3790 3789 ··· 3811 3812 if (dev) { 3812 3813 dev_name_source = dev->name; 3813 3814 /* Terminate the table early */ 3814 - memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0, 3815 - sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL])); 3816 3815 neigh_vars_size = NEIGH_VAR_BASE_REACHABLE_TIME_MS + 1; 3817 3816 } else { 3818 3817 struct neigh_table *tbl = p->tbl;
+6 -7
net/core/sysctl_net_core.c
··· 661 661 .proc_handler = proc_dointvec_minmax, 662 662 .extra1 = SYSCTL_ZERO, 663 663 }, 664 - { } 665 664 }; 666 665 667 666 static struct ctl_table netns_core_table[] = { ··· 697 698 .extra2 = SYSCTL_ONE, 698 699 .proc_handler = proc_dou8vec_minmax, 699 700 }, 700 - { } 701 701 }; 702 702 703 703 static int __init fb_tunnels_only_for_init_net_sysctl_setup(char *str) ··· 714 716 715 717 static __net_init int sysctl_core_net_init(struct net *net) 716 718 { 717 - struct ctl_table *tbl, *tmp; 719 + size_t table_size = ARRAY_SIZE(netns_core_table); 720 + struct ctl_table *tbl; 718 721 719 722 tbl = netns_core_table; 720 723 if (!net_eq(net, &init_net)) { 724 + int i; 721 725 tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL); 722 726 if (tbl == NULL) 723 727 goto err_dup; 724 728 725 - for (tmp = tbl; tmp->procname; tmp++) 726 - tmp->data += (char *)net - (char *)&init_net; 729 + for (i = 0; i < table_size; ++i) 730 + tbl[i].data += (char *)net - (char *)&init_net; 727 731 } 728 732 729 - net->core.sysctl_hdr = register_net_sysctl_sz(net, "net/core", tbl, 730 - ARRAY_SIZE(netns_core_table)); 733 + net->core.sysctl_hdr = register_net_sysctl_sz(net, "net/core", tbl, table_size); 731 734 if (net->core.sysctl_hdr == NULL) 732 735 goto err_reg; 733 736
-2
net/dccp/sysctl.c
··· 90 90 .mode = 0644, 91 91 .proc_handler = proc_dointvec_ms_jiffies, 92 92 }, 93 - 94 - { } 95 93 }; 96 94 97 95 static struct ctl_table_header *dccp_table_header;
+1 -5
net/ieee802154/6lowpan/reassembly.c
··· 338 338 .mode = 0644, 339 339 .proc_handler = proc_dointvec_jiffies, 340 340 }, 341 - { } 342 341 }; 343 342 344 343 /* secret interval has been deprecated */ ··· 350 351 .mode = 0644, 351 352 .proc_handler = proc_dointvec_jiffies, 352 353 }, 353 - { } 354 354 }; 355 355 356 356 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net) ··· 368 370 goto err_alloc; 369 371 370 372 /* Don't export sysctls to unprivileged users */ 371 - if (net->user_ns != &init_user_ns) { 372 - table[0].procname = NULL; 373 + if (net->user_ns != &init_user_ns) 373 374 table_size = 0; 374 - } 375 375 } 376 376 377 377 table[0].data = &ieee802154_lowpan->fqdir->high_thresh;
+6 -7
net/mpls/af_mpls.c
··· 1377 1377 .proc_handler = mpls_conf_proc, 1378 1378 .data = MPLS_PERDEV_SYSCTL_OFFSET(input_enabled), 1379 1379 }, 1380 - { } 1381 1380 }; 1382 1381 1383 1382 static int mpls_dev_sysctl_register(struct net_device *dev, 1384 1383 struct mpls_dev *mdev) 1385 1384 { 1386 1385 char path[sizeof("net/mpls/conf/") + IFNAMSIZ]; 1386 + size_t table_size = ARRAY_SIZE(mpls_dev_table); 1387 1387 struct net *net = dev_net(dev); 1388 1388 struct ctl_table *table; 1389 1389 int i; ··· 1395 1395 /* Table data contains only offsets relative to the base of 1396 1396 * the mdev at this point, so make them absolute. 1397 1397 */ 1398 - for (i = 0; i < ARRAY_SIZE(mpls_dev_table); i++) { 1398 + for (i = 0; i < table_size; i++) { 1399 1399 table[i].data = (char *)mdev + (uintptr_t)table[i].data; 1400 1400 table[i].extra1 = mdev; 1401 1401 table[i].extra2 = net; ··· 1403 1403 1404 1404 snprintf(path, sizeof(path), "net/mpls/conf/%s", dev->name); 1405 1405 1406 - mdev->sysctl = register_net_sysctl_sz(net, path, table, 1407 - ARRAY_SIZE(mpls_dev_table)); 1406 + mdev->sysctl = register_net_sysctl_sz(net, path, table, table_size); 1408 1407 if (!mdev->sysctl) 1409 1408 goto free; 1410 1409 ··· 2652 2653 .extra1 = SYSCTL_ONE, 2653 2654 .extra2 = &ttl_max, 2654 2655 }, 2655 - { } 2656 2656 }; 2657 2657 2658 2658 static int mpls_net_init(struct net *net) 2659 2659 { 2660 + size_t table_size = ARRAY_SIZE(mpls_table); 2660 2661 struct ctl_table *table; 2661 2662 int i; 2662 2663 ··· 2672 2673 /* Table data contains only offsets relative to the base of 2673 2674 * the mdev at this point, so make them absolute. 2674 2675 */ 2675 - for (i = 0; i < ARRAY_SIZE(mpls_table) - 1; i++) 2676 + for (i = 0; i < table_size; i++) 2676 2677 table[i].data = (char *)net + (uintptr_t)table[i].data; 2677 2678 2678 2679 net->mpls.ctl = register_net_sysctl_sz(net, "net/mpls", table, 2679 - ARRAY_SIZE(mpls_table)); 2680 + table_size); 2680 2681 if (net->mpls.ctl == NULL) { 2681 2682 kfree(table); 2682 2683 return -ENOMEM;
-1
net/unix/sysctl_net_unix.c
··· 19 19 .mode = 0644, 20 20 .proc_handler = proc_dointvec 21 21 }, 22 - { } 23 22 }; 24 23 25 24 int __net_init unix_sysctl_register(struct net *net)