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

net: Remove ctl_table sentinel elements from several networking subsystems

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/)

To avoid lots of small commits, this commit brings together network
changes from (as they appear in MAINTAINERS) LLC, MPTCP, NETROM NETWORK
LAYER, PHONET PROTOCOL, ROSE NETWORK LAYER, RXRPC SOCKETS, SCTP
PROTOCOL, SHARED MEMORY COMMUNICATIONS (SMC), TIPC NETWORK LAYER and
NETWORKING [IPSEC]

* Remove sentinel element from ctl_table structs.
* Replace empty array registration with the register_net_sysctl_sz call
in llc_sysctl_init
* Replace the for loop stop condition that tests for procname == NULL
with one that depends on array size in sctp_sysctl_net_register
* Remove instances where an array element is zeroed out to make it look
like a sentinel in xfrm_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
* 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
73dbd8cf ca5d1fce

+9 -26
+2 -6
net/llc/sysctl_net_llc.c
··· 44 44 .mode = 0644, 45 45 .proc_handler = proc_dointvec_jiffies, 46 46 }, 47 - { }, 48 - }; 49 - 50 - static struct ctl_table llc_station_table[] = { 51 - { }, 52 47 }; 53 48 54 49 static struct ctl_table_header *llc2_timeout_header; ··· 51 56 52 57 int __init llc_sysctl_init(void) 53 58 { 59 + struct ctl_table empty[1] = {}; 54 60 llc2_timeout_header = register_net_sysctl(&init_net, "net/llc/llc2/timeout", llc2_timeout_table); 55 - llc_station_header = register_net_sysctl(&init_net, "net/llc/station", llc_station_table); 61 + llc_station_header = register_net_sysctl_sz(&init_net, "net/llc/station", empty, 0); 56 62 57 63 if (!llc2_timeout_header || !llc_station_header) { 58 64 llc_sysctl_exit();
-1
net/mptcp/ctrl.c
··· 156 156 .mode = 0644, 157 157 .proc_handler = proc_dointvec_jiffies, 158 158 }, 159 - {} 160 159 }; 161 160 162 161 static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet)
-1
net/netrom/sysctl_net_netrom.c
··· 140 140 .extra1 = &min_reset, 141 141 .extra2 = &max_reset 142 142 }, 143 - { } 144 143 }; 145 144 146 145 int __init nr_register_sysctl(void)
-1
net/phonet/sysctl.c
··· 81 81 .mode = 0644, 82 82 .proc_handler = proc_local_port_range, 83 83 }, 84 - { } 85 84 }; 86 85 87 86 int __init phonet_sysctl_init(void)
-1
net/rose/sysctl_net_rose.c
··· 112 112 .extra1 = &min_window, 113 113 .extra2 = &max_window 114 114 }, 115 - { } 116 115 }; 117 116 118 117 void __init rose_register_sysctl(void)
-1
net/rxrpc/sysctl.c
··· 127 127 .extra1 = (void *)SYSCTL_ONE, 128 128 .extra2 = (void *)&four, 129 129 }, 130 - { } 131 130 }; 132 131 133 132 int __init rxrpc_sysctl_init(void)
+3 -7
net/sctp/sysctl.c
··· 80 80 .mode = 0644, 81 81 .proc_handler = proc_dointvec, 82 82 }, 83 - 84 - { /* sentinel */ } 85 83 }; 86 84 87 85 /* The following index defines are used in sctp_sysctl_net_register(). ··· 382 384 .extra1 = SYSCTL_ZERO, 383 385 .extra2 = &pf_expose_max, 384 386 }, 385 - 386 - { /* sentinel */ } 387 387 }; 388 388 389 389 static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write, ··· 593 597 594 598 int sctp_sysctl_net_register(struct net *net) 595 599 { 600 + size_t table_size = ARRAY_SIZE(sctp_net_table); 596 601 struct ctl_table *table; 597 602 int i; 598 603 ··· 601 604 if (!table) 602 605 return -ENOMEM; 603 606 604 - for (i = 0; table[i].data; i++) 607 + for (i = 0; i < table_size; i++) 605 608 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp; 606 609 607 610 table[SCTP_RTO_MIN_IDX].extra2 = &net->sctp.rto_max; ··· 610 613 table[SCTP_PS_RETRANS_IDX].extra1 = &net->sctp.pf_retrans; 611 614 612 615 net->sctp.sysctl_header = register_net_sysctl_sz(net, "net/sctp", 613 - table, 614 - ARRAY_SIZE(sctp_net_table)); 616 + table, table_size); 615 617 if (net->sctp.sysctl_header == NULL) { 616 618 kfree(table); 617 619 return -ENOMEM;
+3 -3
net/smc/smc_sysctl.c
··· 90 90 .extra1 = &conns_per_lgr_min, 91 91 .extra2 = &conns_per_lgr_max, 92 92 }, 93 - { } 94 93 }; 95 94 96 95 int __net_init smc_sysctl_net_init(struct net *net) 97 96 { 97 + size_t table_size = ARRAY_SIZE(smc_table); 98 98 struct ctl_table *table; 99 99 100 100 table = smc_table; ··· 105 105 if (!table) 106 106 goto err_alloc; 107 107 108 - for (i = 0; i < ARRAY_SIZE(smc_table) - 1; i++) 108 + for (i = 0; i < table_size; i++) 109 109 table[i].data += (void *)net - (void *)&init_net; 110 110 } 111 111 112 112 net->smc.smc_hdr = register_net_sysctl_sz(net, "net/smc", table, 113 - ARRAY_SIZE(smc_table)); 113 + table_size); 114 114 if (!net->smc.smc_hdr) 115 115 goto err_reg; 116 116
-1
net/tipc/sysctl.c
··· 91 91 .mode = 0644, 92 92 .proc_handler = proc_doulongvec_minmax, 93 93 }, 94 - {} 95 94 }; 96 95 97 96 int tipc_register_sysctl(void)
+1 -4
net/xfrm/xfrm_sysctl.c
··· 38 38 .mode = 0644, 39 39 .proc_handler = proc_dointvec 40 40 }, 41 - {} 42 41 }; 43 42 44 43 int __net_init xfrm_sysctl_init(struct net *net) ··· 56 57 table[3].data = &net->xfrm.sysctl_acq_expires; 57 58 58 59 /* Don't export sysctls to unprivileged users */ 59 - if (net->user_ns != &init_user_ns) { 60 - table[0].procname = NULL; 60 + if (net->user_ns != &init_user_ns) 61 61 table_size = 0; 62 - } 63 62 64 63 net->xfrm.sysctl_hdr = register_net_sysctl_sz(net, "net/core", table, 65 64 table_size);