Skip to content

Commit

Permalink
net: Remove ctl_table sentinel elements from several networking subsy…
Browse files Browse the repository at this point in the history
…stems

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>
  • Loading branch information
Joelgranados authored and davem330 committed May 3, 2024
1 parent ca5d1fc commit 73dbd8c
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 26 deletions.
8 changes: 2 additions & 6 deletions net/llc/sysctl_net_llc.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,16 @@ static struct ctl_table llc2_timeout_table[] = {
.mode = 0644,
.proc_handler = proc_dointvec_jiffies,
},
{ },
};

static struct ctl_table llc_station_table[] = {
{ },
};

static struct ctl_table_header *llc2_timeout_header;
static struct ctl_table_header *llc_station_header;

int __init llc_sysctl_init(void)
{
struct ctl_table empty[1] = {};
llc2_timeout_header = register_net_sysctl(&init_net, "net/llc/llc2/timeout", llc2_timeout_table);
llc_station_header = register_net_sysctl(&init_net, "net/llc/station", llc_station_table);
llc_station_header = register_net_sysctl_sz(&init_net, "net/llc/station", empty, 0);

if (!llc2_timeout_header || !llc_station_header) {
llc_sysctl_exit();
Expand Down
1 change: 0 additions & 1 deletion net/mptcp/ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ static struct ctl_table mptcp_sysctl_table[] = {
.mode = 0644,
.proc_handler = proc_dointvec_jiffies,
},
{}
};

static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet)
Expand Down
1 change: 0 additions & 1 deletion net/netrom/sysctl_net_netrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ static struct ctl_table nr_table[] = {
.extra1 = &min_reset,
.extra2 = &max_reset
},
{ }
};

int __init nr_register_sysctl(void)
Expand Down
1 change: 0 additions & 1 deletion net/phonet/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ static struct ctl_table phonet_table[] = {
.mode = 0644,
.proc_handler = proc_local_port_range,
},
{ }
};

int __init phonet_sysctl_init(void)
Expand Down
1 change: 0 additions & 1 deletion net/rose/sysctl_net_rose.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ static struct ctl_table rose_table[] = {
.extra1 = &min_window,
.extra2 = &max_window
},
{ }
};

void __init rose_register_sysctl(void)
Expand Down
1 change: 0 additions & 1 deletion net/rxrpc/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ static struct ctl_table rxrpc_sysctl_table[] = {
.extra1 = (void *)SYSCTL_ONE,
.extra2 = (void *)&four,
},
{ }
};

int __init rxrpc_sysctl_init(void)
Expand Down
10 changes: 3 additions & 7 deletions net/sctp/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ static struct ctl_table sctp_table[] = {
.mode = 0644,
.proc_handler = proc_dointvec,
},

{ /* sentinel */ }
};

/* The following index defines are used in sctp_sysctl_net_register().
Expand Down Expand Up @@ -384,8 +382,6 @@ static struct ctl_table sctp_net_table[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = &pf_expose_max,
},

{ /* sentinel */ }
};

static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
Expand Down Expand Up @@ -597,14 +593,15 @@ static int proc_sctp_do_probe_interval(struct ctl_table *ctl, int write,

int sctp_sysctl_net_register(struct net *net)
{
size_t table_size = ARRAY_SIZE(sctp_net_table);
struct ctl_table *table;
int i;

table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
if (!table)
return -ENOMEM;

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

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

net->sctp.sysctl_header = register_net_sysctl_sz(net, "net/sctp",
table,
ARRAY_SIZE(sctp_net_table));
table, table_size);
if (net->sctp.sysctl_header == NULL) {
kfree(table);
return -ENOMEM;
Expand Down
6 changes: 3 additions & 3 deletions net/smc/smc_sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ static struct ctl_table smc_table[] = {
.extra1 = &conns_per_lgr_min,
.extra2 = &conns_per_lgr_max,
},
{ }
};

int __net_init smc_sysctl_net_init(struct net *net)
{
size_t table_size = ARRAY_SIZE(smc_table);
struct ctl_table *table;

table = smc_table;
Expand All @@ -105,12 +105,12 @@ int __net_init smc_sysctl_net_init(struct net *net)
if (!table)
goto err_alloc;

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

net->smc.smc_hdr = register_net_sysctl_sz(net, "net/smc", table,
ARRAY_SIZE(smc_table));
table_size);
if (!net->smc.smc_hdr)
goto err_reg;

Expand Down
1 change: 0 additions & 1 deletion net/tipc/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ static struct ctl_table tipc_table[] = {
.mode = 0644,
.proc_handler = proc_doulongvec_minmax,
},
{}
};

int tipc_register_sysctl(void)
Expand Down
5 changes: 1 addition & 4 deletions net/xfrm/xfrm_sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ static struct ctl_table xfrm_table[] = {
.mode = 0644,
.proc_handler = proc_dointvec
},
{}
};

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

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

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

0 comments on commit 73dbd8c

Please sign in to comment.