Skip to content

Commit 73dbd8c

Browse files
Joelgranadosdavem330
authored andcommitted
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 c899710 ("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>
1 parent ca5d1fc commit 73dbd8c

10 files changed

Lines changed: 9 additions & 26 deletions

File tree

net/llc/sysctl_net_llc.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,16 @@ static struct ctl_table llc2_timeout_table[] = {
4444
.mode = 0644,
4545
.proc_handler = proc_dointvec_jiffies,
4646
},
47-
{ },
48-
};
49-
50-
static struct ctl_table llc_station_table[] = {
51-
{ },
5247
};
5348

5449
static struct ctl_table_header *llc2_timeout_header;
5550
static struct ctl_table_header *llc_station_header;
5651

5752
int __init llc_sysctl_init(void)
5853
{
54+
struct ctl_table empty[1] = {};
5955
llc2_timeout_header = register_net_sysctl(&init_net, "net/llc/llc2/timeout", llc2_timeout_table);
60-
llc_station_header = register_net_sysctl(&init_net, "net/llc/station", llc_station_table);
56+
llc_station_header = register_net_sysctl_sz(&init_net, "net/llc/station", empty, 0);
6157

6258
if (!llc2_timeout_header || !llc_station_header) {
6359
llc_sysctl_exit();

net/mptcp/ctrl.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ static struct ctl_table mptcp_sysctl_table[] = {
156156
.mode = 0644,
157157
.proc_handler = proc_dointvec_jiffies,
158158
},
159-
{}
160159
};
161160

162161
static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet)

net/netrom/sysctl_net_netrom.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ static struct ctl_table nr_table[] = {
140140
.extra1 = &min_reset,
141141
.extra2 = &max_reset
142142
},
143-
{ }
144143
};
145144

146145
int __init nr_register_sysctl(void)

net/phonet/sysctl.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ static struct ctl_table phonet_table[] = {
8181
.mode = 0644,
8282
.proc_handler = proc_local_port_range,
8383
},
84-
{ }
8584
};
8685

8786
int __init phonet_sysctl_init(void)

net/rose/sysctl_net_rose.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ static struct ctl_table rose_table[] = {
112112
.extra1 = &min_window,
113113
.extra2 = &max_window
114114
},
115-
{ }
116115
};
117116

118117
void __init rose_register_sysctl(void)

net/rxrpc/sysctl.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ static struct ctl_table rxrpc_sysctl_table[] = {
127127
.extra1 = (void *)SYSCTL_ONE,
128128
.extra2 = (void *)&four,
129129
},
130-
{ }
131130
};
132131

133132
int __init rxrpc_sysctl_init(void)

net/sctp/sysctl.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ static struct ctl_table sctp_table[] = {
8080
.mode = 0644,
8181
.proc_handler = proc_dointvec,
8282
},
83-
84-
{ /* sentinel */ }
8583
};
8684

8785
/* The following index defines are used in sctp_sysctl_net_register().
@@ -384,8 +382,6 @@ static struct ctl_table sctp_net_table[] = {
384382
.extra1 = SYSCTL_ZERO,
385383
.extra2 = &pf_expose_max,
386384
},
387-
388-
{ /* sentinel */ }
389385
};
390386

391387
static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
@@ -597,14 +593,15 @@ static int proc_sctp_do_probe_interval(struct ctl_table *ctl, int write,
597593

598594
int sctp_sysctl_net_register(struct net *net)
599595
{
596+
size_t table_size = ARRAY_SIZE(sctp_net_table);
600597
struct ctl_table *table;
601598
int i;
602599

603600
table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
604601
if (!table)
605602
return -ENOMEM;
606603

607-
for (i = 0; table[i].data; i++)
604+
for (i = 0; i < table_size; i++)
608605
table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
609606

610607
table[SCTP_RTO_MIN_IDX].extra2 = &net->sctp.rto_max;
@@ -613,8 +610,7 @@ int sctp_sysctl_net_register(struct net *net)
613610
table[SCTP_PS_RETRANS_IDX].extra1 = &net->sctp.pf_retrans;
614611

615612
net->sctp.sysctl_header = register_net_sysctl_sz(net, "net/sctp",
616-
table,
617-
ARRAY_SIZE(sctp_net_table));
613+
table, table_size);
618614
if (net->sctp.sysctl_header == NULL) {
619615
kfree(table);
620616
return -ENOMEM;

net/smc/smc_sysctl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ static struct ctl_table smc_table[] = {
9090
.extra1 = &conns_per_lgr_min,
9191
.extra2 = &conns_per_lgr_max,
9292
},
93-
{ }
9493
};
9594

9695
int __net_init smc_sysctl_net_init(struct net *net)
9796
{
97+
size_t table_size = ARRAY_SIZE(smc_table);
9898
struct ctl_table *table;
9999

100100
table = smc_table;
@@ -105,12 +105,12 @@ int __net_init smc_sysctl_net_init(struct net *net)
105105
if (!table)
106106
goto err_alloc;
107107

108-
for (i = 0; i < ARRAY_SIZE(smc_table) - 1; i++)
108+
for (i = 0; i < table_size; i++)
109109
table[i].data += (void *)net - (void *)&init_net;
110110
}
111111

112112
net->smc.smc_hdr = register_net_sysctl_sz(net, "net/smc", table,
113-
ARRAY_SIZE(smc_table));
113+
table_size);
114114
if (!net->smc.smc_hdr)
115115
goto err_reg;
116116

net/tipc/sysctl.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ static struct ctl_table tipc_table[] = {
9191
.mode = 0644,
9292
.proc_handler = proc_doulongvec_minmax,
9393
},
94-
{}
9594
};
9695

9796
int tipc_register_sysctl(void)

net/xfrm/xfrm_sysctl.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ static struct ctl_table xfrm_table[] = {
3838
.mode = 0644,
3939
.proc_handler = proc_dointvec
4040
},
41-
{}
4241
};
4342

4443
int __net_init xfrm_sysctl_init(struct net *net)
@@ -57,10 +56,8 @@ int __net_init xfrm_sysctl_init(struct net *net)
5756
table[3].data = &net->xfrm.sysctl_acq_expires;
5857

5958
/* Don't export sysctls to unprivileged users */
60-
if (net->user_ns != &init_user_ns) {
61-
table[0].procname = NULL;
59+
if (net->user_ns != &init_user_ns)
6260
table_size = 0;
63-
}
6461

6562
net->xfrm.sysctl_hdr = register_net_sysctl_sz(net, "net/core", table,
6663
table_size);

0 commit comments

Comments
 (0)