Skip to content

Commit ce21871

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

File tree

6 files changed

+14
-26
lines changed

6 files changed

+14
-26
lines changed

net/core/neighbour.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3733,7 +3733,7 @@ static int neigh_proc_base_reachable_time(struct ctl_table *ctl, int write,
37333733

37343734
static struct neigh_sysctl_table {
37353735
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];
37373737
} neigh_sysctl_template __read_mostly = {
37383738
.neigh_vars = {
37393739
NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(MCAST_PROBES, "mcast_solicit"),
@@ -3784,7 +3784,6 @@ static struct neigh_sysctl_table {
37843784
.extra2 = SYSCTL_INT_MAX,
37853785
.proc_handler = proc_dointvec_minmax,
37863786
},
3787-
{},
37883787
},
37893788
};
37903789

@@ -3812,8 +3811,6 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
38123811
if (dev) {
38133812
dev_name_source = dev->name;
38143813
/* Terminate the table early */
3815-
memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
3816-
sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
38173814
neigh_vars_size = NEIGH_VAR_BASE_REACHABLE_TIME_MS + 1;
38183815
} else {
38193816
struct neigh_table *tbl = p->tbl;

net/core/sysctl_net_core.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,6 @@ static struct ctl_table net_core_table[] = {
661661
.proc_handler = proc_dointvec_minmax,
662662
.extra1 = SYSCTL_ZERO,
663663
},
664-
{ }
665664
};
666665

667666
static struct ctl_table netns_core_table[] = {
@@ -698,7 +697,6 @@ static struct ctl_table netns_core_table[] = {
698697
.extra2 = SYSCTL_ONE,
699698
.proc_handler = proc_dou8vec_minmax,
700699
},
701-
{ }
702700
};
703701

704702
static int __init fb_tunnels_only_for_init_net_sysctl_setup(char *str)
@@ -716,20 +714,21 @@ __setup("fb_tunnels=", fb_tunnels_only_for_init_net_sysctl_setup);
716714

717715
static __net_init int sysctl_core_net_init(struct net *net)
718716
{
719-
struct ctl_table *tbl, *tmp;
717+
size_t table_size = ARRAY_SIZE(netns_core_table);
718+
struct ctl_table *tbl;
720719

721720
tbl = netns_core_table;
722721
if (!net_eq(net, &init_net)) {
722+
int i;
723723
tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
724724
if (tbl == NULL)
725725
goto err_dup;
726726

727-
for (tmp = tbl; tmp->procname; tmp++)
728-
tmp->data += (char *)net - (char *)&init_net;
727+
for (i = 0; i < table_size; ++i)
728+
tbl[i].data += (char *)net - (char *)&init_net;
729729
}
730730

731-
net->core.sysctl_hdr = register_net_sysctl_sz(net, "net/core", tbl,
732-
ARRAY_SIZE(netns_core_table));
731+
net->core.sysctl_hdr = register_net_sysctl_sz(net, "net/core", tbl, table_size);
733732
if (net->core.sysctl_hdr == NULL)
734733
goto err_reg;
735734

net/dccp/sysctl.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ static struct ctl_table dccp_default_table[] = {
9090
.mode = 0644,
9191
.proc_handler = proc_dointvec_ms_jiffies,
9292
},
93-
94-
{ }
9593
};
9694

9795
static struct ctl_table_header *dccp_table_header;

net/ieee802154/6lowpan/reassembly.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ static struct ctl_table lowpan_frags_ns_ctl_table[] = {
338338
.mode = 0644,
339339
.proc_handler = proc_dointvec_jiffies,
340340
},
341-
{ }
342341
};
343342

344343
/* secret interval has been deprecated */
@@ -351,7 +350,6 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
351350
.mode = 0644,
352351
.proc_handler = proc_dointvec_jiffies,
353352
},
354-
{ }
355353
};
356354

357355
static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
@@ -370,10 +368,8 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
370368
goto err_alloc;
371369

372370
/* Don't export sysctls to unprivileged users */
373-
if (net->user_ns != &init_user_ns) {
374-
table[0].procname = NULL;
371+
if (net->user_ns != &init_user_ns)
375372
table_size = 0;
376-
}
377373
}
378374

379375
table[0].data = &ieee802154_lowpan->fqdir->high_thresh;

net/mpls/af_mpls.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,13 +1377,13 @@ static const struct ctl_table mpls_dev_table[] = {
13771377
.proc_handler = mpls_conf_proc,
13781378
.data = MPLS_PERDEV_SYSCTL_OFFSET(input_enabled),
13791379
},
1380-
{ }
13811380
};
13821381

13831382
static int mpls_dev_sysctl_register(struct net_device *dev,
13841383
struct mpls_dev *mdev)
13851384
{
13861385
char path[sizeof("net/mpls/conf/") + IFNAMSIZ];
1386+
size_t table_size = ARRAY_SIZE(mpls_dev_table);
13871387
struct net *net = dev_net(dev);
13881388
struct ctl_table *table;
13891389
int i;
@@ -1395,16 +1395,15 @@ static int mpls_dev_sysctl_register(struct net_device *dev,
13951395
/* Table data contains only offsets relative to the base of
13961396
* the mdev at this point, so make them absolute.
13971397
*/
1398-
for (i = 0; i < ARRAY_SIZE(mpls_dev_table); i++) {
1398+
for (i = 0; i < table_size; i++) {
13991399
table[i].data = (char *)mdev + (uintptr_t)table[i].data;
14001400
table[i].extra1 = mdev;
14011401
table[i].extra2 = net;
14021402
}
14031403

14041404
snprintf(path, sizeof(path), "net/mpls/conf/%s", dev->name);
14051405

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);
14081407
if (!mdev->sysctl)
14091408
goto free;
14101409

@@ -2653,11 +2652,11 @@ static const struct ctl_table mpls_table[] = {
26532652
.extra1 = SYSCTL_ONE,
26542653
.extra2 = &ttl_max,
26552654
},
2656-
{ }
26572655
};
26582656

26592657
static int mpls_net_init(struct net *net)
26602658
{
2659+
size_t table_size = ARRAY_SIZE(mpls_table);
26612660
struct ctl_table *table;
26622661
int i;
26632662

@@ -2673,11 +2672,11 @@ static int mpls_net_init(struct net *net)
26732672
/* Table data contains only offsets relative to the base of
26742673
* the mdev at this point, so make them absolute.
26752674
*/
2676-
for (i = 0; i < ARRAY_SIZE(mpls_table) - 1; i++)
2675+
for (i = 0; i < table_size; i++)
26772676
table[i].data = (char *)net + (uintptr_t)table[i].data;
26782677

26792678
net->mpls.ctl = register_net_sysctl_sz(net, "net/mpls", table,
2680-
ARRAY_SIZE(mpls_table));
2679+
table_size);
26812680
if (net->mpls.ctl == NULL) {
26822681
kfree(table);
26832682
return -ENOMEM;

net/unix/sysctl_net_unix.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ static struct ctl_table unix_table[] = {
1919
.mode = 0644,
2020
.proc_handler = proc_dointvec
2121
},
22-
{ }
2322
};
2423

2524
int __net_init unix_sysctl_register(struct net *net)

0 commit comments

Comments
 (0)