Skip to content

Commit 1c106eb

Browse files
Joelgranadosdavem330
authored andcommitted
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 c899710 ("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 c899710 ("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>
1 parent ce21871 commit 1c106eb

File tree

11 files changed

+13
-35
lines changed

11 files changed

+13
-35
lines changed

net/ipv4/devinet.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,7 +2520,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
25202520

25212521
static struct devinet_sysctl_table {
25222522
struct ctl_table_header *sysctl_header;
2523-
struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
2523+
struct ctl_table devinet_vars[IPV4_DEVCONF_MAX];
25242524
} devinet_sysctl = {
25252525
.devinet_vars = {
25262526
DEVINET_SYSCTL_COMPLEX_ENTRY(FORWARDING, "forwarding",
@@ -2583,7 +2583,7 @@ static int __devinet_sysctl_register(struct net *net, char *dev_name,
25832583
if (!t)
25842584
goto out;
25852585

2586-
for (i = 0; i < ARRAY_SIZE(t->devinet_vars) - 1; i++) {
2586+
for (i = 0; i < ARRAY_SIZE(t->devinet_vars); i++) {
25872587
t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf;
25882588
t->devinet_vars[i].extra1 = p;
25892589
t->devinet_vars[i].extra2 = net;
@@ -2657,7 +2657,6 @@ static struct ctl_table ctl_forward_entry[] = {
26572657
.extra1 = &ipv4_devconf,
26582658
.extra2 = &init_net,
26592659
},
2660-
{ },
26612660
};
26622661
#endif
26632662

net/ipv4/ip_fragment.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,6 @@ static struct ctl_table ip4_frags_ns_ctl_table[] = {
580580
.proc_handler = proc_dointvec_minmax,
581581
.extra1 = &dist_min,
582582
},
583-
{ }
584583
};
585584

586585
/* secret interval has been deprecated */
@@ -593,7 +592,6 @@ static struct ctl_table ip4_frags_ctl_table[] = {
593592
.mode = 0644,
594593
.proc_handler = proc_dointvec_jiffies,
595594
},
596-
{ }
597595
};
598596

599597
static int __net_init ip4_frags_ns_ctl_register(struct net *net)

net/ipv4/route.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3496,7 +3496,6 @@ static struct ctl_table ipv4_route_table[] = {
34963496
.mode = 0644,
34973497
.proc_handler = proc_dointvec,
34983498
},
3499-
{ }
35003499
};
35013500

35023501
static const char ipv4_route_flush_procname[] = "flush";
@@ -3530,7 +3529,6 @@ static struct ctl_table ipv4_route_netns_table[] = {
35303529
.mode = 0644,
35313530
.proc_handler = proc_dointvec,
35323531
},
3533-
{ },
35343532
};
35353533

35363534
static __net_init int sysctl_route_net_init(struct net *net)
@@ -3548,16 +3546,14 @@ static __net_init int sysctl_route_net_init(struct net *net)
35483546

35493547
/* Don't export non-whitelisted sysctls to unprivileged users */
35503548
if (net->user_ns != &init_user_ns) {
3551-
if (tbl[0].procname != ipv4_route_flush_procname) {
3552-
tbl[0].procname = NULL;
3549+
if (tbl[0].procname != ipv4_route_flush_procname)
35533550
table_size = 0;
3554-
}
35553551
}
35563552

35573553
/* Update the variables to point into the current struct net
35583554
* except for the first element flush
35593555
*/
3560-
for (i = 1; i < ARRAY_SIZE(ipv4_route_netns_table) - 1; i++)
3556+
for (i = 1; i < table_size; i++)
35613557
tbl[i].data += (void *)net - (void *)&init_net;
35623558
}
35633559
tbl[0].extra1 = net;

net/ipv4/sysctl_net_ipv4.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,6 @@ static struct ctl_table ipv4_table[] = {
575575
.extra1 = &sysctl_fib_sync_mem_min,
576576
.extra2 = &sysctl_fib_sync_mem_max,
577577
},
578-
{ }
579578
};
580579

581580
static struct ctl_table ipv4_net_table[] = {
@@ -1502,11 +1501,11 @@ static struct ctl_table ipv4_net_table[] = {
15021501
.proc_handler = proc_dou8vec_minmax,
15031502
.extra1 = SYSCTL_ONE,
15041503
},
1505-
{ }
15061504
};
15071505

15081506
static __net_init int ipv4_sysctl_init_net(struct net *net)
15091507
{
1508+
size_t table_size = ARRAY_SIZE(ipv4_net_table);
15101509
struct ctl_table *table;
15111510

15121511
table = ipv4_net_table;
@@ -1517,7 +1516,7 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
15171516
if (!table)
15181517
goto err_alloc;
15191518

1520-
for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) {
1519+
for (i = 0; i < table_size; i++) {
15211520
if (table[i].data) {
15221521
/* Update the variables to point into
15231522
* the current struct net
@@ -1533,7 +1532,7 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
15331532
}
15341533

15351534
net->ipv4.ipv4_hdr = register_net_sysctl_sz(net, "net/ipv4", table,
1536-
ARRAY_SIZE(ipv4_net_table));
1535+
table_size);
15371536
if (!net->ipv4.ipv4_hdr)
15381537
goto err_reg;
15391538

net/ipv4/xfrm4_policy.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ static struct ctl_table xfrm4_policy_table[] = {
152152
.mode = 0644,
153153
.proc_handler = proc_dointvec,
154154
},
155-
{ }
156155
};
157156

158157
static __net_init int xfrm4_net_sysctl_init(struct net *net)

net/ipv6/addrconf.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7184,14 +7184,12 @@ static const struct ctl_table addrconf_sysctl[] = {
71847184
.extra1 = SYSCTL_ZERO,
71857185
.extra2 = SYSCTL_TWO,
71867186
},
7187-
{
7188-
/* sentinel */
7189-
}
71907187
};
71917188

71927189
static int __addrconf_sysctl_register(struct net *net, char *dev_name,
71937190
struct inet6_dev *idev, struct ipv6_devconf *p)
71947191
{
7192+
size_t table_size = ARRAY_SIZE(addrconf_sysctl);
71957193
int i, ifindex;
71967194
struct ctl_table *table;
71977195
char path[sizeof("net/ipv6/conf/") + IFNAMSIZ];
@@ -7200,7 +7198,7 @@ static int __addrconf_sysctl_register(struct net *net, char *dev_name,
72007198
if (!table)
72017199
goto out;
72027200

7203-
for (i = 0; table[i].data; i++) {
7201+
for (i = 0; i < table_size; i++) {
72047202
table[i].data += (char *)p - (char *)&ipv6_devconf;
72057203
/* If one of these is already set, then it is not safe to
72067204
* overwrite either of them: this makes proc_dointvec_minmax
@@ -7215,7 +7213,7 @@ static int __addrconf_sysctl_register(struct net *net, char *dev_name,
72157213
snprintf(path, sizeof(path), "net/ipv6/conf/%s", dev_name);
72167214

72177215
p->sysctl_header = register_net_sysctl_sz(net, path, table,
7218-
ARRAY_SIZE(addrconf_sysctl));
7216+
table_size);
72197217
if (!p->sysctl_header)
72207218
goto free;
72217219

net/ipv6/icmp.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,6 @@ static struct ctl_table ipv6_icmp_table_template[] = {
12061206
.extra1 = SYSCTL_ZERO,
12071207
.extra2 = SYSCTL_ONE,
12081208
},
1209-
{ },
12101209
};
12111210

12121211
struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)

net/ipv6/reassembly.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,6 @@ static struct ctl_table ip6_frags_ns_ctl_table[] = {
436436
.mode = 0644,
437437
.proc_handler = proc_dointvec_jiffies,
438438
},
439-
{ }
440439
};
441440

442441
/* secret interval has been deprecated */
@@ -449,7 +448,6 @@ static struct ctl_table ip6_frags_ctl_table[] = {
449448
.mode = 0644,
450449
.proc_handler = proc_dointvec_jiffies,
451450
},
452-
{ }
453451
};
454452

455453
static int __net_init ip6_frags_ns_sysctl_register(struct net *net)

net/ipv6/route.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6428,7 +6428,6 @@ static struct ctl_table ipv6_route_table_template[] = {
64286428
.extra1 = SYSCTL_ZERO,
64296429
.extra2 = SYSCTL_ONE,
64306430
},
6431-
{ }
64326431
};
64336432

64346433
struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
@@ -6452,10 +6451,6 @@ struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
64526451
table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss;
64536452
table[9].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval;
64546453
table[10].data = &net->ipv6.sysctl.skip_notify_on_dev_down;
6455-
6456-
/* Don't export sysctls to unprivileged users */
6457-
if (net->user_ns != &init_user_ns)
6458-
table[1].procname = NULL;
64596454
}
64606455

64616456
return table;

net/ipv6/sysctl_net_ipv6.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ static struct ctl_table ipv6_table_template[] = {
213213
.proc_handler = proc_doulongvec_minmax,
214214
.extra2 = &ioam6_id_wide_max,
215215
},
216-
{ }
217216
};
218217

219218
static struct ctl_table ipv6_rotable[] = {
@@ -248,11 +247,11 @@ static struct ctl_table ipv6_rotable[] = {
248247
.proc_handler = proc_dointvec,
249248
},
250249
#endif /* CONFIG_NETLABEL */
251-
{ }
252250
};
253251

254252
static int __net_init ipv6_sysctl_net_init(struct net *net)
255253
{
254+
size_t table_size = ARRAY_SIZE(ipv6_table_template);
256255
struct ctl_table *ipv6_table;
257256
struct ctl_table *ipv6_route_table;
258257
struct ctl_table *ipv6_icmp_table;
@@ -264,7 +263,7 @@ static int __net_init ipv6_sysctl_net_init(struct net *net)
264263
if (!ipv6_table)
265264
goto out;
266265
/* Update the variables to point into the current struct net */
267-
for (i = 0; i < ARRAY_SIZE(ipv6_table_template) - 1; i++)
266+
for (i = 0; i < table_size; i++)
268267
ipv6_table[i].data += (void *)net - (void *)&init_net;
269268

270269
ipv6_route_table = ipv6_route_sysctl_init(net);
@@ -276,8 +275,7 @@ static int __net_init ipv6_sysctl_net_init(struct net *net)
276275
goto out_ipv6_route_table;
277276

278277
net->ipv6.sysctl.hdr = register_net_sysctl_sz(net, "net/ipv6",
279-
ipv6_table,
280-
ARRAY_SIZE(ipv6_table_template));
278+
ipv6_table, table_size);
281279
if (!net->ipv6.sysctl.hdr)
282280
goto out_ipv6_icmp_table;
283281

0 commit comments

Comments
 (0)